5

I'm trying to write my own AngularJS directives. I think I understand the difference between the compile and link functions. This video clears it up nicely.

But I'm not sure now that I understand the role a controller plays in a directive. A directive can include a controller function, and you can inject $element, $attrs and such into it, so it can do pretty much everything that the link function can do and, I believe, the other way around.

So I have two questions:

  1. Are there important technical differences between the controller function and the link function?
  2. What is best practice? What kind of work should I be doing in which?
mhelvens
  • 4,225
  • 4
  • 31
  • 55
  • Ah, yes indeed. Thanks! I wonder why that one didn't show up as a suggestion. I'll also vote to close. – mhelvens Sep 26 '13 at 17:26

0 Answers0