Book Image

AngularJS Web application development Cookbook

By : Matthew Frisbie
Book Image

AngularJS Web application development Cookbook

By: Matthew Frisbie

Overview of this book

Packed with easy-to-follow recipes, this practical guide will show you how to unleash the full might of the AngularJS framework. Skip straight to practical solutions and quick, functional answers to your problems without hand-holding or slogging through the basics. Avoid antipatterns and pitfalls, and squeeze the maximum amount out of the most powerful parts of the framework, from creating promise-driven applications to building an extensible event bus. Throughout, take advantage of a clear problem-solving approach that offers code samples and explanations of components you should be using in your production applications.
Table of Contents (17 chapters)
AngularJS Web Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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. To use it, include it in your application as follows:

(app.js)

angular.module('myApp', ['ngMessages']);

How to do it…

The ngMessages module exists as two separate directives: ng-messages and ng-message. The ng-messages directive defines the error message...