AngularJS templateCache

TemplateCache

TemplaceCache How to

  • ng-template in HTML
  • javascript

ng-template

Write ng-template in HTML

<script type="text/ng-template" id="templteId.html">
	<p>This is the content of the template</p>
</script>

Detect ng-template and automaticaly samve as templateId.html.
We can use templateId.html in directive or include

<div ng-include=" 'templateId.html' "></div>

This example is include

javascript

angular
  .module('firstappApp', [])
  .run(function($templateCache){
    $templateCache.put('templateId.html', '<p>Div</p>');
  });

add run and templatecache put codes.

Use this under directive

'use strict';

angular.module('firstappApp')
  .directive('commonHeader', function($templateCache) {
  	return {
  		restrict: 'E',
  		template: $templateCache.get('templateId.html')
  	};
});