diff --git a/src/ng/templateRequest.js b/src/ng/templateRequest.js index d819de434c1e..a39aac6df1b7 100644 --- a/src/ng/templateRequest.js +++ b/src/ng/templateRequest.js @@ -47,10 +47,8 @@ function $TemplateRequestProvider() { return $http.get(tpl, httpOptions) .then(function(response) { - var html = response.data; self.totalPendingRequests--; - $templateCache.put(tpl, html); - return html; + return response.data; }, handleError); function handleError() { diff --git a/test/ng/templateRequestSpec.js b/test/ng/templateRequestSpec.js index 5684b0c6f42e..bdd58538c1e4 100644 --- a/test/ng/templateRequestSpec.js +++ b/test/ng/templateRequestSpec.js @@ -16,16 +16,24 @@ describe('$templateRequest', function() { expect(content).toBe('
abc
'); })); - it('should cache the request using $templateCache to prevent extra downloads', - inject(function($rootScope, $templateRequest, $templateCache) { + it('should cache the request to prevent extra downloads', + inject(function($rootScope, $templateRequest, $httpBackend) { - $templateCache.put('tpl.html', 'matias'); + $httpBackend.expectGET('tpl.html').respond('matias'); - var content; - $templateRequest('tpl.html').then(function(html) { content = html; }); + var content = []; + function tplRequestCb(html) { + content.push(html); + } + $templateRequest('tpl.html').then(tplRequestCb); + $httpBackend.flush(); + + $templateRequest('tpl.html').then(tplRequestCb); $rootScope.$digest(); - expect(content).toBe('matias'); + + expect(content[0]).toBe('matias'); + expect(content[1]).toBe('matias'); })); it('should throw an error when the template is not found',