O'Reilly logo

Mastering Web Application Development with AngularJS by Pawel Kozlowski, Peter Bacon Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating an asynchronous model validator

Some validation can only be done by interacting with a remote service, say a database. In these cases, the response from the service will be asynchronous. This brings in complication not only in working with model validation asynchronously but also in testing this functionality.

In our Admin User Form, we would like to check whether the e-mail address that a user is entering has already been taken. We will create a uniqueEmail directive, which will check with our back-end server to find if the e-mail address is already in use:

<input ng-model="user.email" unique-email>

Mocking up the Users service

We use the Users resource service to query the database for the e-mail addresses that are already in use. We need ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required