如何从链接函数访问与指令关联的控制器实例?
return {
template: template,
controller: controller,
controllerAs: 'myCtrl', // How do I access the controller instance from the link function?
restrict: 'E',
replace: true,
link: function(scope, element, attrs) {}
};
答案 0 :(得分:1)
指令中的link函数接受第4个参数。您可以执行以下操作:
return {
template: template,
controller: controller,
controllerAs: 'myCtrl',
restrict: 'E',
replace: true,
link: function(scope, element, attrs, controller) {}
};