-4

我在 Angular 中创建了一个指令。当我使用该template属性时,该指令“编译”。使用时不编译templateURL

templateURL 文件在 Angular 页面的控制台或网络选项卡中没有 404。它是 200 作为浏览器 URL。

我错过了什么?

'use strict';

angular.module('mean.profile').directive('inProfileSidebar', function() {
  return {
    restrict: 'A',
    scope: {
      data: '=',
      editable: '=',
    },
    template: '<div><h2>inProfileNarrow</h2><div>{{data}}</div><div>{{editable}}</div></div>',
//    templateURL: '/profile/views/inProfileSidebar.html',
  };
});

我的应用程序的 URL 是:http://localhost:3000/#!/profile/ 这个 URL 是 200:http://localhost:3000/profile/views/inProfileSidebar.html

inProfileSidebar.html

<div>
  <h2>inProfileNarrow</h2>
  <div>{{data}}</div>
  <div>{{editable}}</div>
</div>

在此 HTML 中使用:

<div class="col-md-4">
  <div in-profile-sidebar data="data.profile" editable="data.profile.editable"></div>
</div>

我在浏览器控制台中没有看到任何错误,并且浏览器的网络日志中也没有对 templateURL 的请求。

它在我使用时有效template,但不适用于templateURL. 为什么?

4

1 回答 1

4

我没有对其进行测试,但快速浏览一下,您似乎错误地命名了该属性。

它应该是“templateUrl”,而不是“templateURL”(只有“U”是大写的)。

于 2014-12-10T00:29:22.593 回答