diff --git a/src/ng/templateRequest.js b/src/ng/templateRequest.js index 7b3b04261e56..ff699d6cd0ef 100644 --- a/src/ng/templateRequest.js +++ b/src/ng/templateRequest.js @@ -99,8 +99,7 @@ function $TemplateRequestProvider() { handleRequestFn.totalPendingRequests--; }) .then(function(response) { - $templateCache.put(tpl, response.data); - return response.data; + return $templateCache.put(tpl, response.data); }, handleError); function handleError(resp) { diff --git a/test/ng/templateRequestSpec.js b/test/ng/templateRequestSpec.js index cb9c1c6f6ce8..3ca323613103 100644 --- a/test/ng/templateRequestSpec.js +++ b/test/ng/templateRequestSpec.js @@ -114,6 +114,24 @@ describe('$templateRequest', function() { expect($templateCache.get('tpl.html')).toBe('matias'); })); + it('should return the cached value on the first request', + inject(function($rootScope, $templateRequest, $templateCache, $httpBackend) { + + $httpBackend.expectGET('tpl.html').respond('matias'); + spyOn($templateCache, 'put').and.returnValue('_matias'); + + var content = []; + function tplRequestCb(html) { + content.push(html); + } + + $templateRequest('tpl.html').then(tplRequestCb); + $rootScope.$digest(); + $httpBackend.flush(); + + expect(content[0]).toBe('_matias'); + })); + it('should call `$exceptionHandler` on request error', function() { module(function($exceptionHandlerProvider) { $exceptionHandlerProvider.mode('log');