I have my template pre-loaded in a javascript string array, like var t = JST['firstTemplate']
, where t
would be like,
<div>This scope has a value of {{value}}</div>
How can I use this pre-loaded template in an ng-include
directive?
Note that my template in this scenario can be more complex, with possible nested view and templates and their own nested scopes and controllers. So I am not sure if any of the ng-bind directives would help?
UPDATE:
Looking at the source of ng-include
it appears that a good way to do this would be to decouple the template loading logic into a customizable provider.
The current default loading mechanism simply does a $http.get
with $templateCache
as the cache provider. It seems like I can inject my template content in JST['firstTemplate']
into the template cache, but I'd have to do that at startup time, for every template.
$templateCache.put('firstTemplate', JST['firstTemplate']);
and then have,
<div ng-include="firstTemplate"></div>
I could also write a custom directive that goes side-by side with every ng-include, that somehow does this pre-caching of templates. That again seem clunky.
UPDATE #2
I'm going to try overriding the templateCache, so that it uses my already pre-loaded JST hash. Will post the results if this works.