diff options
| author | Igor Minar | 2012-03-08 15:00:38 -0800 |
|---|---|---|
| committer | Igor Minar | 2012-03-08 22:29:34 -0800 |
| commit | f54db2ccda399f2677e4ca7588018cb31545a2b4 (patch) | |
| tree | 29ef2f8f834544c84cea1a82e3d08679358fb992 /src/directive/script.js | |
| parent | dd7b0f56fcd9785f7fccae8c4f088a8f3e7b125e (diff) | |
| download | angular.js-f54db2ccda399f2677e4ca7588018cb31545a2b4.tar.bz2 | |
chore(directives,widgets): reorg the code under directive/ dir
Diffstat (limited to 'src/directive/script.js')
| -rw-r--r-- | src/directive/script.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/directive/script.js b/src/directive/script.js new file mode 100644 index 00000000..f0affaf9 --- /dev/null +++ b/src/directive/script.js @@ -0,0 +1,42 @@ +'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 + * + * @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()); + } + } + }; +}]; |
