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

Commit 4971ef1

Browse files
committed
fix(ngMessage): make ngMessage compatible with ngBind
Fixes #8089 Closes #13074 BREAKING CHANGE: ngMessage is now compiled with a priority of 1, which means directives on the same element as ngMessage with a priority lower than 1 will be applied when ngMessage calls the $transclude function. Previously, they were applied during the initial compile phase and were passed the comment element created by the transclusion of ngMessage. To restore this behavior, custom directives need to have their priority increased to at least "1".
1 parent 7c792f4 commit 4971ef1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/ngMessages/messages.js

+2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ angular.module('ngMessages', [])
572572
* @ngdoc directive
573573
* @name ngMessageExp
574574
* @restrict AE
575+
* @priority 1
575576
* @scope
576577
*
577578
* @description
@@ -604,6 +605,7 @@ function ngMessageDirectiveFactory() {
604605
return {
605606
restrict: 'AE',
606607
transclude: 'element',
608+
priority: 1, // must run before ngBind, otherwise the text is set on the comment
607609
terminal: true,
608610
require: '^^ngMessages',
609611
link: function(scope, element, attrs, ngMessagesCtrl, $transclude) {

test/ngMessages/messagesSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,46 @@ describe('ngMessages', function() {
372372
expect(trim(element.text())).toEqual("Enter something");
373373
}));
374374

375+
376+
it('should be compatible with ngBind',
377+
inject(function($rootScope, $compile) {
378+
379+
element = $compile('<div ng-messages="col">' +
380+
' <div ng-message="required" ng-bind="errorMessages.required"></div>' +
381+
' <div ng-message="extra" ng-bind="errorMessages.extra"></div>' +
382+
'</div>')($rootScope);
383+
384+
$rootScope.$apply(function() {
385+
$rootScope.col = {
386+
required: true,
387+
extra: true
388+
};
389+
$rootScope.errorMessages = {
390+
required: 'Fill in the text field.',
391+
extra: 'Extra error message.'
392+
};
393+
});
394+
395+
expect(messageChildren(element).length).toBe(1);
396+
expect(trim(element.text())).toEqual('Fill in the text field.');
397+
398+
$rootScope.$apply(function() {
399+
$rootScope.col.required = false;
400+
$rootScope.col.extra = true;
401+
});
402+
403+
expect(messageChildren(element).length).toBe(1);
404+
expect(trim(element.text())).toEqual('Extra error message.');
405+
406+
$rootScope.$apply(function() {
407+
$rootScope.errorMessages.extra = 'New error message.';
408+
});
409+
410+
expect(messageChildren(element).length).toBe(1);
411+
expect(trim(element.text())).toEqual('New error message.');
412+
}));
413+
414+
375415
// issue #12856
376416
it('should only detach the message object that is associated with the message node being removed',
377417
inject(function($rootScope, $compile, $animate) {

0 commit comments

Comments
 (0)