我在 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
. 为什么?