Manipulating the DOM with a Link Function

When the AngularJS HTML compiler encounters a directive, it runs the directive’s compile function, which returns the link() function. The link() function is added to the list of AngularJS directives. After all directives have been compiled, the HTML compiler calls the link() functions in order, based on priority.

If you want to modify the DOM inside a custom directive, you should use a link() function. The link() function accepts the scope, element, attributes, controller, and transclude function associated with the directive, enabling you to manipulate the DOM directly within the directive. The transclude function is a handle that is bound to the transclusion scope.

Inside the link() function, you handle ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.