O'Reilly logo

AngularJS Directives Cookbook by Fernando Monteiro

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 a form directive with custom validation

Continuing within the context of the previous examples, we will now create a custom directive to validate some form fields. This recipe applies to any type of form field; however, we will use the <select> tag.

AngularJS offers some very useful resources for form validation with built-in directives. We will create a component that can be reused elsewhere in our application.

Getting ready

Just as we did in the previous chapters, we will continue using the same application created in the previous recipe.

In this example, we will use an external library called ngMessages.

For the purpose of this example, we just add the library as a dependency in our index.html, using a Content Delivery Network (CDN), as ...

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