Saturday, September 14, 2013

Linkers vs. Controllers in AngularJS Directives

When I first started working with directives, I used linker functions to do all the work.  I enjoy working with controllers over linker functions.  They are simpler.

I have had mixed results using "ng-click" in the linker function. Binding "ng-click" in the controller always works. Not that there is a bug or problem with the linker function.  It is invoked at a different time in the page load life cycle.  With anything, order of operations is important.

The example below shows the same click activity implemented two different ways; as a linker function and as a controller.  The example does not run, but is conceptually correct.  I'm still trying to figure out how to debug efficiently in jsfiddle.

1 comment:

  1. Great source of info on angularjs. We always rely on this blog other than our regular online Angularjs training classes helped me a lot.

    ReplyDelete