Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($templateRequest): cache downloaded templates as strings #10646

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ng/templateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function $TemplateRequestProvider() {

return $http.get(tpl, httpOptions)
.then(function(response) {
$templateCache.put(tpl, response.data);
self.totalPendingRequests--;
return response.data;
}, handleError);
Expand Down
2 changes: 1 addition & 1 deletion src/ngRoute/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ function $RouteProvider() {
return $q.all(locals);
}
}).
// after route change
then(function(locals) {
// after route change
if (nextRoute == $route.current) {
if (nextRoute) {
nextRoute.locals = locals;
Expand Down
3 changes: 2 additions & 1 deletion test/ng/templateRequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('$templateRequest', function() {
}));

it('should cache the request to prevent extra downloads',
inject(function($rootScope, $templateRequest, $httpBackend) {
inject(function($rootScope, $templateRequest, $templateCache, $httpBackend) {

$httpBackend.expectGET('tpl.html').respond('matias');

Expand All @@ -34,6 +34,7 @@ describe('$templateRequest', function() {

expect(content[0]).toBe('matias');
expect(content[1]).toBe('matias');
expect($templateCache.get('tpl.html')).toBe('matias');
}));

it('should throw an error when the template is not found',
Expand Down