【问题标题】:Template not loading in angular 1.5 directive模板未在 Angular 1.5 指令中加载
【发布时间】:2016-09-19 09:14:55
【问题描述】:

我在网站上似乎有很多这样的问题,但没有一个对我有用。

我在 app.js 中有这个

   (function(){
           var app = angular.module("freelingApp", ["ngRoute"]);
           app.controller("MainController",
                   ["$http", "$scope",
                   function($http, $scope){
                          ...some code here...
                  }]);
          app.directive("dataTable", function(){
                                     return{
                                             transclude:true,
                                             replace:true,
                                             restrict: 'E',
                                             templateUrl:'data-table.html'
                                     };
                                   });

})();

app.js 和 data-table.html 都在目录中的同一级

我的 index.html 是这样的:

<html>
  <head>
   ... some code here ...
  </head>

   <body ng-app="freelingApp" ng-controller="MainController">
       ... some code here...
       <div>
          <data-table></data-table>
       </div>
   </body>
</html>

而我的data-table.html的内容(暂时因为我在测试)是:

<h1>Hello world!</h1>

谁能告诉我如何解决这个问题?

【问题讨论】:

  • 您能否提供您的data-table.html 相对于您的index.html 的正确位置以及您在浏览器中本地使用的完整URL?

标签: javascript angularjs frontend


【解决方案1】:

如果你使用templateUrl,它应该是相对于web root url; 请参考:Angular directive templateUrl relative to .js file

【讨论】:

    【解决方案2】:

    显然问题出在我使用的另一个框架 Django 上,因此将模板相对 URL 更改为绝对 URL 解决了问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      相关资源
      最近更新 更多