forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng.$templateCache.html
40 lines (40 loc) · 1.87 KB
/
ng.$templateCache.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<a href="http://github.com/angular/angular.js/tree/v1.2.8/src/ng/cacheFactory.js#L196" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/cacheFactory.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$templateCache</code>
<div><span class="hint">service in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="ng-templatecache-page"><p>The first time a template is used, it is loaded in the template cache for quick retrieval. You
can load templates directly into the cache in a <code>script</code> tag, or by consuming the
<code>$templateCache</code> service directly.</p>
<p>Adding via the <code>script</code> tag:
<pre class="prettyprint linenums">
<html ng-app>
<head>
<script type="text/ng-template" id="templateId.html">
This is the content of the template
</script>
</head>
...
</html>
</pre>
<p><strong>Note:</strong> the <code>script</code> tag containing the template does not need to be included in the <code>head</code> of
the document, but it must be below the <code>ng-app</code> definition.</p>
<p>Adding via the $templateCache service:</p>
<pre class="prettyprint linenums">
var myApp = angular.module('myApp', []);
myApp.run(function($templateCache) {
$templateCache.put('templateId.html', 'This is the content of the template');
});
</pre>
<p>To retrieve the template later, simply use it in your HTML:
<pre class="prettyprint linenums">
<div ng-include=" 'templateId.html' "></div>
</pre>
<p>or get it via Javascript:
<pre class="prettyprint linenums">
$templateCache.get('templateId.html')
</pre>
<p>See <a href="api/ng.$cacheFactory"><code>$cacheFactory</code></a>.</p>
</div></div>
</div>