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

fix($templateRequest): always return the template that is stored in the cache #16434

Merged
merged 1 commit into from
Feb 5, 2018
Merged
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
3 changes: 1 addition & 2 deletions src/ng/templateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/ng/templateRequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down