13

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 Answer 1

14

Did you try to add leading slash to templateUrl, like

templateUrl: '/ng-templates/myTemplate.html', 
Sign up to request clarification or add additional context in comments.

5 Comments

yes i tried. but it doesn't work. I thought it was supposed to work according to this post: stackoverflow.com/questions/16887018/…
I had a problem when using an absolute url in a directive's templateUrl, the test wouldn't work when the $httpbackend was mocked out, it would be hitting a non-existent URL.
I just had the same issue, your browser was caching the previous (most likely blank) template. Need to do a hard refresh/clear cache to get the new template (why it worked).
is it possible to assign a value of a variable like this, var mypath='http:localhost/testapp/'; templateUrl: mypath+'/ng-templates/myTemplate.html',
Sir, you've just saved my day! I wish I could upvote more times

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.