While reading the documentation I can see usage of both: link method and directive options.
Can both of these options be present in directive declaration at the same time?
Asked
Active
Viewed 27 times
0

Mike
- 20,010
- 25
- 97
- 140
-
link is one of the options you can use. I don't really understand your question – Deblaton Jean-Philippe Dec 27 '16 at 15:22
-
and controller is one of the options I can use, so question is: can I use both options in the directive declaration at the same time? – Mike Dec 27 '16 at 15:24
-
If you mean `link` vs `controller` in a directive, you'd use the second when you want to expose functionality with other directives. Otherwise use `link`. – Stubbies Dec 27 '16 at 15:24
-
so what if I want 'to expose functionality' and 'manipulate the DOM'? – Mike Dec 27 '16 at 15:25
-
there is more than 2 options (you have compile, pre-link, post-link, controller). You can use alll of them together. You can google "directive lifecycle" for more explanation – Deblaton Jean-Philippe Dec 27 '16 at 15:25
-
2Maybe this helps: http://stackoverflow.com/questions/15676614/angularjs-link-vs-compile-vs-controller?rq=1 – Maria Ines Parnisari Dec 27 '16 at 15:25
-
You can't use 'compile' and 'link' together. You must choose what 'phase' fits better to you. Is it the same with 'link' and 'controller' for a directive declaration, or they can be used side by side? – Mike Dec 27 '16 at 15:29
-
You can use link, compile and controller together - no problem. – Petr Averyanov Dec 27 '16 at 15:33
1 Answers
0
So all can be used together, thanks Deblaton.
.directive("directiveName",function () {
return {
controller: function() {
// controller code here...
},
compile: {
// compile code here...
return {
pre: function() {
// pre-link code here...
},
post: function() {
// post-link code here...
}
};
}
}
})

Mike
- 20,010
- 25
- 97
- 140