Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular js templateUrl with absolute path

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'?

like image 883
Yujun Wu Avatar asked Jul 17 '13 20:07

Yujun Wu


1 Answers

Did you try to add leading slash to templateUrl, like

templateUrl: '/ng-templates/myTemplate.html', 
like image 155
Artem Latyshev Avatar answered Oct 26 '22 07:10

Artem Latyshev