aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2012-01-24 22:42:33 -0800
committerMisko Hevery2012-01-25 11:50:37 -0800
commite2b1d9e994e50bcd01d237302a3357bc7ebb6fa5 (patch)
treea49246c84ba1dc0c34525fbe9819d5f649282be5
parent9ee2cdff44e7d496774b340de816344126c457b3 (diff)
downloadangular.js-e2b1d9e994e50bcd01d237302a3357bc7ebb6fa5.tar.bz2
feat(scriptTemplateLoader): provide template inlining
populates $templateCache with content of ng-template scripts
-rw-r--r--src/AngularPublic.js1
-rw-r--r--src/widgets.js12
-rw-r--r--test/widgetsSpec.js18
3 files changed, 31 insertions, 0 deletions
diff --git a/src/AngularPublic.js b/src/AngularPublic.js
index 516bbad4..d052c35b 100644
--- a/src/AngularPublic.js
+++ b/src/AngularPublic.js
@@ -69,6 +69,7 @@ function publishExternalAPI(angular){
input: inputDirective,
textarea: inputDirective,
form: ngFormDirective,
+ script: scriptTemplateLoader,
select: selectDirective,
option: optionDirective,
ngBind: ngBindDirective,
diff --git a/src/widgets.js b/src/widgets.js
index cf32bdc1..68c40b92 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -813,3 +813,15 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
});
};
}];
+
+
+var scriptTemplateLoader = ['$templateCache', function($templateCache) {
+ return {
+ compile: function(element, attr) {
+ if (attr.type == 'text/ng-template') {
+ var templateUrl = attr.id;
+ $templateCache.put(templateUrl, element.text());
+ }
+ }
+ };
+}];
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 6e115a36..53766274 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -931,4 +931,22 @@ describe('widget', function() {
}));
});
});
+
+
+ describe('scriptTemplateLoader', function() {
+ it('should populate $templateCache with contents of a ng-template script element', inject(
+ function($compile, $templateCache) {
+ if (msie <=8) return;
+ // in ie8 it is not possible to create a script tag with the right content.
+ // it always comes up as empty. I was trying to set the text of the
+ // script tag, but that did not work either, so I gave up.
+ $compile('<div>foo' +
+ '<script id="/ignore">ignore me</script>' +
+ '<script type="text/ng-template" id="/myTemplate.html"><x>{{y}}</x></script>' +
+ '</div>' );
+ expect($templateCache.get('/myTemplate.html')).toBe('<x>{{y}}</x>');
+ expect($templateCache.get('/ignore')).toBeUndefined();
+ }
+ ));
+ });
});