diff options
| author | Misko Hevery | 2012-03-23 14:03:24 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2012-03-28 11:16:35 -0700 | 
| commit | 2430f52bb97fa9d682e5f028c977c5bf94c5ec38 (patch) | |
| tree | e7529b741d70199f36d52090b430510bad07f233 /src/ng/directive/script.js | |
| parent | 944098a4e0f753f06b40c73ca3e79991cec6c2e2 (diff) | |
| download | angular.js-2430f52bb97fa9d682e5f028c977c5bf94c5ec38.tar.bz2 | |
chore(module): move files around in preparation for more modules
Diffstat (limited to 'src/ng/directive/script.js')
| -rw-r--r-- | src/ng/directive/script.js | 43 | 
1 files changed, 43 insertions, 0 deletions
| diff --git a/src/ng/directive/script.js b/src/ng/directive/script.js new file mode 100644 index 00000000..4090ae24 --- /dev/null +++ b/src/ng/directive/script.js @@ -0,0 +1,43 @@ +'use strict'; + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.script + * + * @description + * Load content of a script tag, with type `text/ng-template`, into `$templateCache`, so that the + * template can be used by `ng-include`, `ng-view` or directive templates. + * + * @restrict E + * @param {'text/ng-template'} type must be set to `'text/ng-template'` + * + * @example +  <doc:example> +    <doc:source> +      <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> +    </doc:source> +    <doc:scenario> +      it('should load template defined inside script tag', function() { +        element('#tpl-link').click(); +        expect(element('#tpl-content').text()).toMatch(/Content of the template/); +      }); +    </doc:scenario> +  </doc:example> + */ +var scriptDirective = ['$templateCache', function($templateCache) { +  return { +    restrict: 'E', +    terminal: true, +    compile: function(element, attr) { +      if (attr.type == 'text/ng-template') { +        var templateUrl = attr.id; +        $templateCache.put(templateUrl, element.text()); +      } +    } +  }; +}]; | 
