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

fix(ngMessages): create new scope for ngMessage, clean it up correctly #14308

Merged
merged 1 commit into from
Jun 10, 2016
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: 2 additions & 1 deletion src/ngMessages/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ function ngMessageDirectiveFactory() {
},
attach: function() {
if (!currentElement) {
$transclude(scope, function(elm) {
$transclude(function(elm, newScope) {
$animate.enter(elm, null, element);
currentElement = elm;

Expand All @@ -700,6 +700,7 @@ function ngMessageDirectiveFactory() {
ngMessagesCtrl.deregister(commentNode);
messageCtrl.detach();
}
newScope.$destroy();
});
});
}
Expand Down
28 changes: 28 additions & 0 deletions test/ngMessages/messagesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,34 @@ describe('ngMessages', function() {
});
});


it('should clean-up the ngMessage scope when a message is removed',
inject(function($compile, $rootScope) {

var html =
'<div ng-messages="items">' +
'<div ng-message="a">{{forA}}</div>' +
'</div>';

element = $compile(html)($rootScope);
$rootScope.$apply(function() {
$rootScope.forA = 'A';
$rootScope.items = {a: true};
});

expect(element.text()).toBe('A');
var watchers = $rootScope.$countWatchers();

$rootScope.$apply('items.a = false');

expect(element.text()).toBe('');
// We don't know exactly how many watchers are on the scope, only that there should be
// one less now
expect($rootScope.$countWatchers()).toBe(watchers - 1);
})
);


describe('when including templates', function() {
they('should work with a dynamic collection model which is managed by ngRepeat',
{'<div ng-messages-include="...">': '<div ng-messages="item">' +
Expand Down