AngularJS: API: ng/directive/script


script

  1. - directive in module ng

Load the content of a <script> element into $templateCache, so that the template can be used by ngInclude, ngView, or directives. The type of the <script> element must be specified as text/ng-template, and a cache name for the template must be assigned through the element's id, which can then be used as a directive's templateUrl.

Directive Info

  • This directive executes at priority level 0.

Usage

  • as element:
    <script
      type=""
      id="">...</script>

Arguments

ParamTypeDetails
typestring

Must be set to 'text/ng-template'.

idstring

Cache name of the template.

Example

index.html
<script type="text/ng-template" id="/tpl.html">
  Content of the template.</script>

<a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a><div id="tpl-content" ng-include src="currentTpl"></div>
protractor.js
it('should load template defined inside script tag', function() {
  element(by.css('#tpl-link')).click();
  expect(element(by.css('#tpl-content')).getText()).toMatch(/Content of the template/);});