2

In my directive, I'd like to set the html of the element based on a template url:

element.html('some url to a template html file');

instead of

element.html('<div>test</div>').show(); 

how can I do that ?

EDIT

I do not wish to use templateUrl because the template must be dynamic. The template will change according to a scope variable set on the directive. Sorry if I haven't made myself clear before.

4
  • 4
    How about using templateUrl: url in the directive Commented Oct 3, 2013 at 15:20
  • You should read: stackoverflow.com/questions/14994391/… Commented Oct 3, 2013 at 16:19
  • What do you mean by "the template must be dynamic" ? Does that mean that you will have different html templates and you need to dynamically select which one to display, or that the actual HTML markup in the template will change based on some scope variable? Commented Oct 3, 2013 at 17:54
  • first scenario. I will have different html templates and based on a value passed to the directive, the template will change. Commented Oct 3, 2013 at 18:17

1 Answer 1

1

I suppose if you really want to do this you will have to use the $compile service. Maybe try to take a look at this answer.

Sign up to request clarification or add additional context in comments.

1 Comment

excellent. I was already using $compile, but the answer was to use $http and $templateCache. 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.