Building Your Own Directives
While you can get a long way using just controllers and the built-in directives that
come with AngularJS, there will inevitably come a point in the development of your
application where you will need to teach your browser some new tricks by building
your own directives. The main reasons why you would want to develop custom
directives are:
- You need to manipulate the DOM directly, such as with JQuery
- You want to refactor parts of your application to remove repeated codes
- You want to create new HTML mark-up for non-developers to use,
such as designers
This chapter will introduce you to developing your own AngularJS directives.
Directives appear in many different places and have different uses. In this chapter
we will show:
- How to define a directive
- Examples of the most common types of directive and how to code them
- Directives that rely on each other
- How to unit test directives