desmondlee desmondlee - 5 months ago 80
AngularJS Question

Using ng-include with template cache

I am developing in angular js. Previously, i use ng-include with url. But how could i point the url to templatecache?

<ng-include
src="string"
[onload="string"]
[autoscroll="string"]>
...
</ng-include>

Answer

Template cache uses a key for identifying the cached elements, so you can use the key for that.

  $templateCache.put('MY KEY', 'Cached content');

And in the html:

<ng-include src="'MY KEY'"></ng-include>

See it on AngularJS docs for $templateCache.

Comments