mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 23:40:23 +00:00
we now have two types of namespaces: - true namespace: angular.* - used for all global apis - virtual namespace: ng.*, ngMock.*, ... - used for all DI modules the virual namespaces have services under the second namespace level (e.g. ng.) and filters and directives prefixed with filter: and directive: respectively (e.g. ng.filter:orderBy, ng.directive:ngRepeat) this simplifies urls and makes them a lot shorter while still avoiding name collisions
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @ngdoc directive
|
|
* @name ng.directive:script
|
|
*
|
|
* @description
|
|
* Load content of a script tag, with type `text/ng-template`, into `$templateCache`, so that the
|
|
* template can be used by `ngInclude`, `ngView` 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,
|
|
// IE is not consistent, in scripts we have to read .text but in other nodes we have to read .textContent
|
|
text = element[0].text;
|
|
|
|
$templateCache.put(templateUrl, text);
|
|
}
|
|
}
|
|
};
|
|
}];
|