Skip to content

Commit 8ece832

Browse files
committed
feat(ngMessages): provide support for dynamic message resolution
Prior to this fix it was impossible to apply a binding to a the ngMessage directive to represent the name of the error. It was also not possible to use ngRepeat or any other structural directive to dynamically update the list of messages. This fix ensures that both the ngMessage and ngMessages directives automatically update when any dynamic message data changes. BREAKING CHANGE: The ngMessage directive now uses expressions. Therefore, all pre-existing ngMessage attribute values (as well as the values assigned via the `when` attribute) will not function as they did before because ngMessage will evaluate the attribute value as an expression. A quick fix for this is to wrap single quotes around each of the attribute values: ```html <!-- AngularJS 1.3.x --> <div ng-message="required">Your message is required</div> <!-- AngularJS 1.4.x --> <div ng-message="'required'">Your message is required</div> ``` The `ngMessagesInclude` attribute is now its own directive and that must be placed as a **child** element within the element with the ngMessages directive. (Keep in mind that the former behaviour of the ngMessageInclude attribute was that all **included** ngMessage template code was placed at the **bottom** of the element containing the ngMessages directive; therefore to make this behave in the same way, place the element containing the ngMessagesInclude directive at the end of the container containing the ngMessages directive). ```html <!-- AngularJS 1.3.x --> <div ng-messages="model.$error" ng-messages-include="remote.html"> <div ng-message="required">Your message is required</div> </div> <!-- AngularJS 1.4.x --> <div ng-messages="model.$error"> <div ng-message="'required'">Your message is required</div> <div ng-messages-include="remote.html"></div> </div> ``` Closes angular#10036 Closes angular#9338
1 parent e1132f5 commit 8ece832

File tree

2 files changed

+447
-220
lines changed

2 files changed

+447
-220
lines changed

0 commit comments

Comments
 (0)