mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-01 03:44:41 +00:00
feat(scriptTemplateLoader): provide template inlining
populates $templateCache with content of ng-template scripts
This commit is contained in:
parent
9ee2cdff44
commit
e2b1d9e994
3 changed files with 31 additions and 0 deletions
|
|
@ -69,6 +69,7 @@ function publishExternalAPI(angular){
|
||||||
input: inputDirective,
|
input: inputDirective,
|
||||||
textarea: inputDirective,
|
textarea: inputDirective,
|
||||||
form: ngFormDirective,
|
form: ngFormDirective,
|
||||||
|
script: scriptTemplateLoader,
|
||||||
select: selectDirective,
|
select: selectDirective,
|
||||||
option: optionDirective,
|
option: optionDirective,
|
||||||
ngBind: ngBindDirective,
|
ngBind: ngBindDirective,
|
||||||
|
|
|
||||||
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}];
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
}
|
||||||
|
));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue