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).(似乎我可以在link
函数或controller
函数中执行此操作(因为它们都可以访问范围)。)
When is it the case when I have to use link
function and not the 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 */ }
};
}
Also, I understand that link
is the non-angular world.
(另外,我知道link
是非角度的世界。)
So, I can use $watch
, $digest
and $apply
.(所以,我可以使用$watch
, $digest
和$apply
。)
What is the significance of the link
function, when we already had controller?
(当我们已经拥有控制器时, link
功能有什么意义?)
ask by Yugal Jindle translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…