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

Commit 52ceec2

Browse files
cmichalvojtajina
authored andcommitted
fix(templateRequest): allow empty html template
allow empty html template and not throw error Closes #9581
1 parent 38d12de commit 52ceec2

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

src/ng/templateRequest.js

-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ function $TemplateRequestProvider() {
4848
return $http.get(tpl, httpOptions)
4949
.then(function(response) {
5050
var html = response.data;
51-
if (!html || html.length === 0) {
52-
return handleError();
53-
}
54-
5551
self.totalPendingRequests--;
5652
$templateCache.put(tpl, html);
5753
return html;

test/ng/templateRequestSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('$templateRequest', function() {
4343
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: tpl.html');
4444
}));
4545

46-
it('should throw an error when the template is empty',
46+
it('should not throw an error when the template is empty',
4747
inject(function($rootScope, $templateRequest, $httpBackend) {
4848

4949
$httpBackend.expectGET('tpl.html').respond('');
@@ -55,7 +55,7 @@ describe('$templateRequest', function() {
5555
expect(function() {
5656
$rootScope.$digest();
5757
$httpBackend.flush();
58-
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: tpl.html');
58+
}).not.toThrow();
5959
}));
6060

6161
it('should keep track of how many requests are going on',

test/ngRoute/directive/ngViewSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('ngView', function() {
5656
});
5757

5858

59-
it('should not instantiate the associated controller when an empty template is downloaded', function() {
59+
it('should instantiate the associated controller when an empty template is downloaded', function() {
6060
var log = [], controllerScope,
6161
Ctrl = function($scope) {
6262
controllerScope = $scope;
@@ -73,9 +73,9 @@ describe('ngView', function() {
7373

7474
expect(function() {
7575
$rootScope.$digest();
76-
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: /tpl.html');
76+
}).not.toThrow();
7777

78-
expect(controllerScope).toBeUndefined();
78+
expect(controllerScope).toBeDefined();
7979
});
8080
});
8181

test/ngRoute/routeSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ describe('$route', function() {
744744
});
745745

746746

747-
it('should throw an error when a template is empty or not found', function() {
747+
it('should throw an error when a template is not found', function() {
748748
module(function($routeProvider, $exceptionHandlerProvider) {
749749
$exceptionHandlerProvider.mode('log');
750750
$routeProvider.
@@ -766,7 +766,7 @@ describe('$route', function() {
766766
$rootScope.$digest();
767767

768768
$httpBackend.flush();
769-
expect($exceptionHandler.errors.pop().message).toContain("[$compile:tpload] Failed to load template: r2.html");
769+
expect($exceptionHandler.errors.length).toBe(0);
770770

771771
$httpBackend.expectGET('r3.html').respond('abc');
772772
$location.path('/r3');

0 commit comments

Comments
 (0)