我需要对范围和模板执行一些操作.似乎我可以在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
是无Angular 的世界.所以,我可以用$watch
,$digest
和$apply
.
当我们已经有了控制器时,link
函数的意义是什么?