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

5.1. Introduction to directives

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.

5.1.1. What are directives?

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.”

5.1.2. Why we need directives

5.2. Directives 101: a quick foundation

5.3. A more advanced feature

5.4. Integrating with third-party libraries again!

5.5. Testing a directive

5.6. Best practices

5.7. Summary

sitemap