【问题标题】:Angular directive not rendering with templateUrl in ionic appAngular 指令未在离子应用程序中使用 templateUrl 呈现
【发布时间】:2017-05-13 10:41:08
【问题描述】:

在 chrome 中 - 两种 变体都有效。但是,在模拟 ios 时 - 使用 templateUrl 的指令确实工作。

在 ios 模拟器中不起作用,但在浏览器中起作用:

angular.directive('listitems', function(ApiEndpoint) {
  return {
    restrict: 'A',
    templateUrl: '../template/listitems.ng.html',
    scope: true
  };
})

适用于ios模拟器并适用于浏览器

angular.directive('listitems', function(ApiEndpoint) {
  return {
    restrict: 'A',
    template: '<strong>listitems</strong>',
    scope: true
  };
})

在其他地方使用 templateUrl 在浏览器和 ios 模拟器中都可以正常工作。例如,当使用 ui 路由器时 - 我能够毫无问题地加载外部模板:

$stateProvider.state('app.dashboard', {
  url: "/dashboard",
  views: {
    'menuContent': {
      templateUrl: '../template/dashboard.ng.html',
      controller: 'DigstackDashboard'
    }
  }
});

我的问题是 - 在指令的情况下,为什么 templateUrl 值不能只在 ios 模拟器中工作?

【问题讨论】:

  • 我会更新我的问题 - ApiEndpoint 是一个常量
  • 请告诉我listitems.ng.html的整个路径
  • [app]/www/templates/listitems.ng.html 请注意,此路径在浏览器中渲染时可以正常工作 - 并且在使用 ui-router 时也是如此。只是没有指令。
  • 您使用哪个服务器来运行应用程序?
  • 我正在运行 gulp remove-proxy && ionic emulate ios --target="iPhone-5" 来启动模拟器。我正在使用 vagrant 运行我的服务 - 并修改了我的 /etc/hosts 文件以接受来自配置域的流量。

标签: angularjs ionic-framework angularjs-directive


【解决方案1】:

找到问题了!我希望这对其他人有帮助。

angular.config(function($sceDelegateProvider){
    $sceDelegateProvider.resourceUrlWhitelist([
         'self',
         'https://www.example.com/**'
    ]);
 }

即使在 uirouter - 这似乎不需要。在 ios 模拟器中 - 需要此配置才能加载模板。

【讨论】:

    猜你喜欢
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多