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

Commit 8c3a42c

Browse files
refactor($templateRequest): avoid double calls to $templateCache.put
Closes #10265
1 parent 96e7897 commit 8c3a42c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/ng/templateRequest.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ function $TemplateRequestProvider() {
4242

4343
return $http.get(tpl, httpOptions)
4444
.then(function(response) {
45-
var html = response.data;
4645
self.totalPendingRequests--;
47-
$templateCache.put(tpl, html);
48-
return html;
46+
return response.data;
4947
}, handleError);
5048

5149
function handleError(resp) {

test/ng/templateRequestSpec.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,24 @@ describe('$templateRequest', function() {
1616
expect(content).toBe('<div>abc</div>');
1717
}));
1818

19-
it('should cache the request using $templateCache to prevent extra downloads',
20-
inject(function($rootScope, $templateRequest, $templateCache) {
19+
it('should cache the request to prevent extra downloads',
20+
inject(function($rootScope, $templateRequest, $httpBackend) {
2121

22-
$templateCache.put('tpl.html', 'matias');
22+
$httpBackend.expectGET('tpl.html').respond('matias');
2323

24-
var content;
25-
$templateRequest('tpl.html').then(function(html) { content = html; });
24+
var content = [];
25+
function tplRequestCb(html) {
26+
content.push(html);
27+
}
2628

29+
$templateRequest('tpl.html').then(tplRequestCb);
30+
$httpBackend.flush();
31+
32+
$templateRequest('tpl.html').then(tplRequestCb);
2733
$rootScope.$digest();
28-
expect(content).toBe('matias');
34+
35+
expect(content[0]).toBe('matias');
36+
expect(content[1]).toBe('matias');
2937
}));
3038

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

0 commit comments

Comments
 (0)