【问题标题】:Angular directive templateURL not being loaded. Why? [closed]未加载 Angular 指令 templateURL。为什么? [关闭]
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

    • 就是这样!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2015-07-05
    • 2014-05-14
    • 2018-07-12
    相关资源
    最近更新 更多