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

fix(ngMessagesInclude): do not compile template if scope is destroyed #14640

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/ngMessages/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ angular.module('ngMessages', [])
link: function($scope, element, attrs) {
var src = attrs.ngMessagesInclude || attrs.src;
$templateRequest(src).then(function(html) {
if ($scope.$$destroyed) return;

$compile(html)($scope, function(contents) {
element.after(contents);

Expand Down
19 changes: 19 additions & 0 deletions test/ngMessages/messagesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,25 @@ describe('ngMessages', function() {
})
);

it('should not throw if scope has been destroyed when template request is ready',
inject(function($rootScope, $httpBackend, $compile) {
$httpBackend.expectGET('messages.html').respond('<div ng-message="a">A</div>');
$rootScope.show = true;
var html =
'<div ng-if="show">' +
'<div ng-messages="items">' +
'<div ng-messages-include="messages.html"></div>' +
'</div>' +
'</div>';

element = $compile(html)($rootScope);
$rootScope.$digest();
$rootScope.show = false;
$rootScope.$digest();
expect(function() {
$httpBackend.flush();
}).not.toThrow();
}));
});

describe('when multiple', function() {
Expand Down