Chapter 5. Directives
This chapter covers
- What directives are and why they’re helpful
- Different kinds of directives and what they’re best suited for
- The main components that make up a directive
- Some directives we use in Angello
Welcome to the world of directives: one of the most powerful and important features of the AngularJS framework. In this chapter we’ll build three directives for Angello and discuss the techniques and reasoning behind each one. We’ll start out simple and work our way up in complexity to some really neat things you can use in your own web applications.
AngularJS proclaims that it’s “HTML enhanced for web apps!” What does it mean to enhance HTML?
HTML was born from a mentality rooted in print media, which was quite appropriate at the time. Browsers were limited, and the best you could hope for was to lay out content on a page much like you would a magazine or a newspaper. But fast-forward to the modern browser and HTML is incredibly limited and fixed when it comes to performing modern tasks like handling dynamic content, interactions, animations, and so on.
AngularJS solves this limitation by allowing you to define your own HTML behavior with directives. Directives are essentially custom HTML tags and attributes that you can create to do some very clever things. And by “clever,” we mean “anything you want.”