在带有url的视频观看页面上
/watch/video_id
,我有一个 ng 应用程序。该指令如下所示。
app.directive('myApp', function() {
return {
restrict: 'E',
templateUrl: 'ng-templates/myTemplate.html',
link: function(scope, elem, attrs) {
},
controller: 'Controller'
};
});
由于templateUrl是相对路径,所以会尝试在
中寻找模板'/watch/ng-templates/myTemplate.html'
这是一个错误。
我想把所有的模板都放在ng-templates文件夹中。但是如果 ng 应用程序总是寻找相对路径,它就不会工作。有没有办法配置应用程序以使其查找“/ng-template/myTemplate.html”?
最佳答案
您是否尝试将前导斜线添加到 templateUrl,例如
templateUrl: '/ng-templates/myTemplate.html',
关于javascript - 具有绝对路径的angular js templateUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17709405/