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.

Sam
  • 13,934
  • 26
  • 108
  • 194
  • 4
    How about using `templateUrl: url` in the directive – tymeJV Oct 03 '13 at 15:20
  • You should read: http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background – TheHippo Oct 03 '13 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? – kmdsax Oct 03 '13 at 17:54
  • first scenario. I will have different html templates and based on a value passed to the directive, the template will change. – Sam Oct 03 '13 at 18:17

1 Answers1

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.

Community
  • 1
  • 1
Daniel Perez
  • 6,335
  • 4
  • 24
  • 28
  • excellent. I was already using $compile, but the answer was to use $http and $templateCache. Thanks ! – Sam Oct 03 '13 at 18:38