I need to perform some operations on scope and the template. It seems that I can do that in either the link
function or the controller
function (since both have access to the scope).
When is it the case when I have to use link
function and not the controller?
angular.module('myApp').directive('abc', function($timeout) {
return {
restrict: 'EA',
replace: true,
transclude: true,
scope: true,
link: function(scope, elem, attr) { /* link function */ },
controller: function($scope, $element) { /* controller function */ }
};
}
Also, I understand that link
is the non-angular world. So, I can use $watch
, $digest
and $apply
.
What is the significance of the link
function, when we already had controller?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…