带绝对路径的 angular js templateUrl [英] angular js templateUrl with absolute path
问题描述
在带有网址的视频观看页面上
On the video watch page with the url
/watch/video_id
/watch/video_id
,我有一个 ng 应用程序.指令如下所示.
, 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'
};
});
由于templateUrl是相对路径,它会尝试在
Since the templateUrl is the relative path, it will try to find the template in
'/watch/ng-templates/myTemplate.html'
'/watch/ng-templates/myTemplate.html'
这是一个错误.
我想把所有的模板放在 ng-templates 文件夹中.但是如果 ng 应用程序总是寻找相对路径,它就行不通.有没有办法配置应用程序使其查找/ng-template/myTemplate.html"?
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'?
推荐答案
您是否尝试在 templateUrl 中添加前导斜杠,例如
Did you try to add leading slash to templateUrl, like
templateUrl: '/ng-templates/myTemplate.html',
这篇关于带绝对路径的 angular js templateUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!