diff --git a/src/ng/templateRequest.js b/src/ng/templateRequest.js index 4d3989ce4904..81cea32d750a 100644 --- a/src/ng/templateRequest.js +++ b/src/ng/templateRequest.js @@ -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); diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index ad7bbc710b48..56ec491a207e 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -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; diff --git a/test/ng/templateRequestSpec.js b/test/ng/templateRequestSpec.js index 2b695d6ab300..f4a245c86437 100644 --- a/test/ng/templateRequestSpec.js +++ b/test/ng/templateRequestSpec.js @@ -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'); @@ -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',