Skip to content

Commit c683596

Browse files
Spencerctrahey
Spencer
authored andcommitted
docs($templateCache): add examples of usage
1 parent afdc483 commit c683596

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/ng/cacheFactory.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,44 @@ function $CacheFactoryProvider() {
194194
* @name ng.$templateCache
195195
*
196196
* @description
197-
* Cache used for storing html templates.
198-
*
197+
* The first time a template is used, it is loaded in the tempalte cache for quick retrieval. You can
198+
* load templates directly into the cache in a `script` tag, or by consuming the `$templateCache`
199+
* service directly.
200+
*
201+
* Adding via the `script` tag:
202+
* <pre>
203+
* <html ng-app>
204+
* <head>
205+
* <script type="text/ng-template" id="templateId.html">
206+
* This is the content of the template
207+
* </script>
208+
* </head>
209+
* ...
210+
* </html>
211+
* </pre>
212+
*
213+
* **Note:** the `script` tag containing the template does not need to be included in the `head` of the document, but
214+
* it must be below the `ng-app` definition.
215+
*
216+
* Adding via the $templateCache service:
217+
*
218+
* <pre>
219+
* var myApp = angular.module('myApp', []);
220+
* myApp.run(function($templateCache) {
221+
* $templateCache.put('templateId.html', 'This is the content of the template');
222+
* });
223+
* </pre>
224+
*
225+
* To retrieve the template later, simply use it in your HTML:
226+
* <pre>
227+
* <div ng-include=" 'templateId.html' "></div>
228+
* </pre>
229+
*
230+
* or get it via Javascript:
231+
* <pre>
232+
* $templateCache.get('templateId.html')
233+
* </pre>
234+
*
199235
* See {@link ng.$cacheFactory $cacheFactory}.
200236
*
201237
*/

0 commit comments

Comments
 (0)