0

I have a problem with AngularJs directive. The directive is working fine when I'm using "template". But when I'm trying to work with "templateURL".

The js file of the directive and the html file for the template are in the same directory. In the template file theres the same code as in the template field in my directive.

my directive

project tree

Why is this not working? I don't understand it.

Thanks for your help!

3
  • I don't see any question here! Commented Feb 22, 2016 at 19:41
  • The templateUrl in your directive, are you setting a path to the correct file? templateUrl: "test.html" Commented Feb 22, 2016 at 19:47
  • Could you create a plunker ? Commented Feb 22, 2016 at 19:55

1 Answer 1

1

You need to provide the absolute path for the templateUrl field. Try this,

templateUrl : 'js/directive/test.html'
Sign up to request clarification or add additional context in comments.

3 Comments

I tried to change it to your solution but it isn't working. Sorry, I'm new to AngularJS
Looked on it a second time. Your answer is correct without the first backslash. But I don't understand why this is working. Is there an easy explanation for that? My thought was that the js file and html file are in the same directory. So i could just write test.html into the directive.
templateUrl field will look for path/to/the/template. It cant take a file name and load it. So you have to specify the path instead of file name. Thanks.

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.