fix(ngMessagesInclude): do not compile template if scope is destroyed
Messages imported with `ngMessagesInclude` are loaded asynchronously and they can arrive after the ngMessages element has already been removed from DOM. Previously we tried to compile these messages and that caused a `$compile:ctreq` error. Now they are silently ignored if `ngMessagesInclude`'s scope has already been destroyed. Closes #12695 Closes #14640
This commit is contained in:
committed by
Peter Bacon Darwin
parent
e67c3f8ab6
commit
ab247d6203
@@ -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);
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user