Book Image

Data Oriented Development with Angularjs

Book Image

Data Oriented Development with Angularjs

Overview of this book

Table of Contents (17 chapters)
Data-oriented Development with AngularJS
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Directives


The HTML code (without the directives) is still made up of divs after divs nested inside one another, and those divs make no semantic sense; except for the various class attribute values that you attach to them (or however else you have tried to give them meaning). But wouldn't it be nice if you could instead, structure your HTML like this:

<employee id="1"></employee>

Or maybe like this:

<address type="corporate"></address>

Then, you get a nice little piece of UI which displays the full address or information of the employee.

So what are directives? To repeat an oft-quoted cliché, directives teach old HTML some new tricks, and they are the ones which help us in writing custom controls. So we should write directives when we want to refactor repeated (HTML) code, to create new HTML markup and when we need to manipulate the DOM directly.

As per Angular, it is an anti-pattern to manipulate the DOM in your controllers. You must use directives for any kind of DOM...