diff --git a/src/ngMessages/messages.js b/src/ngMessages/messages.js index 9a5020fe8397..52d1699d3b55 100644 --- a/src/ngMessages/messages.js +++ b/src/ngMessages/messages.js @@ -572,6 +572,7 @@ angular.module('ngMessages', []) * @ngdoc directive * @name ngMessageExp * @restrict AE + * @priority 1 * @scope * * @description @@ -604,6 +605,7 @@ function ngMessageDirectiveFactory() { return { restrict: 'AE', transclude: 'element', + priority: 1, // must run before ngBind, otherwise the text is set on the comment terminal: true, require: '^^ngMessages', link: function(scope, element, attrs, ngMessagesCtrl, $transclude) { diff --git a/test/ngMessages/messagesSpec.js b/test/ngMessages/messagesSpec.js index 3d4f1100f06c..d30b3a328a34 100644 --- a/test/ngMessages/messagesSpec.js +++ b/test/ngMessages/messagesSpec.js @@ -372,6 +372,46 @@ describe('ngMessages', function() { expect(trim(element.text())).toEqual("Enter something"); })); + + it('should be compatible with ngBind', + inject(function($rootScope, $compile) { + + element = $compile('
' + + '
' + + '
' + + '
')($rootScope); + + $rootScope.$apply(function() { + $rootScope.col = { + required: true, + extra: true + }; + $rootScope.errorMessages = { + required: 'Fill in the text field.', + extra: 'Extra error message.' + }; + }); + + expect(messageChildren(element).length).toBe(1); + expect(trim(element.text())).toEqual('Fill in the text field.'); + + $rootScope.$apply(function() { + $rootScope.col.required = false; + $rootScope.col.extra = true; + }); + + expect(messageChildren(element).length).toBe(1); + expect(trim(element.text())).toEqual('Extra error message.'); + + $rootScope.$apply(function() { + $rootScope.errorMessages.extra = 'New error message.'; + }); + + expect(messageChildren(element).length).toBe(1); + expect(trim(element.text())).toEqual('New error message.'); + })); + + // issue #12856 it('should only detach the message object that is associated with the message node being removed', inject(function($rootScope, $compile, $animate) {