AngularJS Essentials
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Chapter 2<br />
The next properties that we are going to study are considered more complex and<br />
reserved for advanced components. They are required every time we need to deal<br />
with the DOM or interact with other directives. These properties are link, require,<br />
controller, and compile.<br />
link<br />
Another important feature while creating directives is the ability to access the<br />
DOM in order to interact with its elements. To achieve this mission, we need to<br />
implement a function called link in our directive. The link function is invoked after<br />
the framework is compiled, and it is recommended that you add behavior to the<br />
directive. It takes five arguments as follows:<br />
• scope: This is the scope object of the directive<br />
• element: This is the element instance of directive<br />
• attrs: This is the list of attributes declared within the directive's element<br />
• ctrl: This is the controller of the require directive, and it will be available<br />
only if it is used with the require property<br />
• transcludeFn: This is the transclude function<br />
The following code shows the accordion directive using the link function:<br />
index.html<br />
<br />
White - 10/10/2002 10:00<br />
<br />
<br />
Black - 10/10/2002 10:36<br />
[ 43 ]<br />
www.it-ebooks.info