16.07.2017 Views

AngularJS Essentials

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Data Handling<br />

To finish, we can add a regular expression to validate the format of the plate.<br />

This can be done through the ngPattern directive:<br />

<br />

The result can be evaluated through the implicit object $valid. It will be defined<br />

based on the directives of each field. If any of these violate the directives definition,<br />

the result will be false. Also, the $invalid object can be used, considering its<br />

usefulness, depending on the purpose:<br />

<br />

Park<br />

<br />

If the plate is not valid, the following alert should be displayed:<br />

<br />

The plate is invalid!<br />

<br />

However, there is a problem with this approach. The alert is displayed even if we<br />

type nothing and this might confuse the user. To prevent such situations, there are<br />

two properties that we need to understand, which are covered in the next section.<br />

[ 64 ]<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!