Angular JS: What Is The Need Of The Directive’s Link Function When We Already Had Directive’s Controller With Scope?
Answer : After my initial struggle with the link and controller functions and reading quite a lot about them, I think now I have the answer. First lets understand , How do angular directives work in a nutshell: We begin with a template (as a string or loaded to a string) var templateString = '<div my-directive>{{5 + 10}}</div>'; Now, this templateString is wrapped as an angular element var el = angular.element(templateString); With el , now we compile it with $compile to get back the link function. var l = $compile(el) Here is what happens, $compile walks through the whole template and collects all the directives that it recognizes. All the directives that are discovered are compiled recursively and their link functions are collected. Then, all the link functions are wrapped in a new link function and returned as l . Finally, we provide scope function to this l (link) function which further executes the wrapped link functions ...