【发布时间】:2014-12-10 00:09:40
【问题描述】:
我在 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',
};
});
我的应用网址是:http://localhost:3000/#!/profile/
这个网址是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 一起使用。为什么?
【问题讨论】:
标签: angularjs angularjs-directive mean.io