我需要对作用域和模板执行一些操作。似乎我可以在link函数或controller函数中这样做(因为两者都可以访问作用域)。
什么情况下,当我必须使用link函数而不是控制器?
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 */ }
};
}
而且,我知道link是非角世界。因此,我可以使用$watch, $digest和$apply。
当我们已经有了控制器时,link函数的意义是什么?