angular js templateUrl with absolute path

自古美人都是妖i 提交于 2019-12-03 11:50:37

问题


On the video watch page with the url

/watch/video_id

, I had a ng app. The directive is shown as below.

app.directive('myApp', function() {
    return {
      restrict: 'E',
      templateUrl: 'ng-templates/myTemplate.html', 
      link: function(scope, elem, attrs) {
      },
      controller: 'Controller'
    };
  }); 

Since the templateUrl is the relative path, it will try to find the template in

'/watch/ng-templates/myTemplate.html'

which is an error.

I want to put all the templates in the ng-templates folder. But it won't work if the ng app always looks for the relative path. Is there a way to configure the app making it to look for '/ng-template/myTemplate.html'?


回答1:


Did you try to add leading slash to templateUrl, like

templateUrl: '/ng-templates/myTemplate.html', 


来源:https://stackoverflow.com/questions/17709405/angular-js-templateurl-with-absolute-path

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