14 Creating attribute directives
This chapter covers
- Creating custom directives that modify a single HTML element
- Configuring and applying custom directives
- Receiving data in a custom directive
- Using the directive lifecycle API
- Generating custom events from directives
- Creating directives that support template variables
In this chapter, I describe how custom directives can be used to supplement the functionality provided by the built-in ones of Angular. The focus of this chapter is attribute directives, which are the simplest type that can be created and that change the appearance or behavior of a single element. In chapter 14, I explain how to create structural directives, which are used to change the layout of the HTML document. Components are also a type of directive, and I explain how they work in chapter 15.
Throughout these chapters, I describe how custom directives work by re-creating the features provided by some of the built-in directives. This isn’t something you would typically do in a real project, but it provides a useful baseline against which the process can be explained. Table 14.1 puts attribute directives into context.