Angular directive templateURL not being loaded. Why? [closed]

允我心安 提交于 2019-12-27 07:29:28

问题


I've created a directive in Angular. The directive 'compiles' when I use the template attribute. It doesn't compile in when using templateURL.

The templateURL file doesn't 404 in angular page's console or network tab. It is 200 as a browser URL.

What am I missing?

'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',
  };
});

My app's URL is: http://localhost:3000/#!/profile/ This URL is 200: http://localhost:3000/profile/views/inProfileSidebar.html

inProfileSidebar.html

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

Used in this HTML:

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

I don't see any errors in the browser console, and there is no request to the templateURL in the browser's network log.

It works when I use template, but not with templateURL. Why?


回答1:


I didnt test it, but from a quick look it seems you named the property incorrectly.

It should be 'templateUrl', NOT 'templateURL' (only the 'U' is uppercase).



来源:https://stackoverflow.com/questions/27391254/angular-directive-templateurl-not-being-loaded-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!