0

How do I evaluate a template, recevied via AJAX?

Let's say I have a directive, that sets a click-listener to its host element, so on click it makes an ajax-call, receives some angular-based template, evaluates it, and shows some modal popup?

The main problem is that as a client, I dont exactly know what template to fetch, the server handles that, based on received parameters

$http.post( '... url ...' , {
  'param': value,
   ... 
}).success(function (ans) {
 // evaluate and create popup here
});

Thanks in advance!

Eugene
  • 195
  • 1
  • 1
  • 10

1 Answers1

0

Your directive's template could have a <div ng-iclude="scopedVar.templateUrl"></div>

Whenever scopedVar.templateUrl changes, the template will get loaded and compiled/linked (all this magic you're missing). Keep in mind that ng-include will also cache the template inside $templateCache (will only be asked once).

Kos Prov
  • 4,207
  • 1
  • 18
  • 14
  • Thank you very much! That was not the solution I finnaly applied, but this made me think in right direction. – Eugene Nov 07 '13 at 08:45