O'Reilly logo

Mastering AngularJS Directives by Josh Kurz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing the stopwatch

Most directives use a link function to achieve their functionality in collaboration with AngularJS scope objects. This is because the link function is usually all that is required to accomplish most requirements that a directive has. The reason the link function (post link) is so useful is because it is always run when the directive's DOM and child scope have been attached to their associated AngularJS scope. This allows us to ensure that all the data properties are present and all the DOM elements have been compiled into an AngularJS context.

In this case, we are using a basic child scope declaration for the directive. This allows for the directive to achieve its functionality inside of its own private scope, which inherits ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required