Cleaning up form errors with ngMessages

The addition of the ngMessages directive aims to solve the problem of erratic and complicated organization of error messages in forms. Traditionally, error messages were handled individually and independently, and they also incorporated some semblance of meta-logic in order to decide which messages should take priority, how many should be seen, and so on. The naïve solution is usually accomplished by sprinkling fistfuls of ng-if directives in the page corresponding to the error message corpus and delegating the display logic to the form controller. As you can imagine, this can get messy very quickly in the wake of complex forms.

Getting ready

The ngMessages directive comes packaged in the ngMessage module. ...

Get AngularJS Web Application Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.