The nitty-gritty of compile and link functions inside AngularJS directives

added by JavaScript Kicks
9/17/2014 11:39:36 AM


Most tutorials briefly mention the compile function as used mainly by AngularJS internally and then advise you to just use the link function as it should cover most use cases for custom directives. That is very unfortunate because understanding the exact differences between those functions will greatly enhance your ability to understand the inner workings of AngularJS and to write better custom directives yourself. So stay with me and by the end of this article you will know exactly what these functions are and when you should use them.