带有绝对路径的angular js templateUrl

Yuj*_* Wu 13 javascript angularjs angularjs-directive

在带有网址的视频观看页面上

/手表/ VIDEO_ID

,我有一个应用程序.该指令如下所示.

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

由于templateUrl是相对路径,因此它将尝试在中找到模板

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

这是一个错误.

我想将所有模板放在ng-templates文件夹中.但是如果ng app总是寻找相对路径,它将无法工作.有没有办法配置应用程序,使其寻找'/ng-template/myTemplate.html'?

Art*_*hev 13

您是否尝试将前导斜杠添加到templateUrl,例如

templateUrl: '/ng-templates/myTemplate.html', 
Run Code Online (Sandbox Code Playgroud)