简体   繁体   English

如何在角度指令中访问控制器

[英]How can I access controller in angular directive

I want to access controller in angular directive. 我想以角度指令访问控制器。 How can I do that? 我怎样才能做到这一点?

I have a link function in the directive and I want to access the controller passed to the directive. 我在指令中有一个链接函数,我想访问传递给该指令的控制器。

The link function's 4th parameter gives you access to the controller instance. 链接功能的第四个参数使您可以访问控制器实例。

return {
            template: template,
            controller: controller,
            controllerAs: 'myCtrl', 
            restrict: 'E',
            replace: true,
            link: function(scope, element, attrs, controller) {}
         };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从调用控制器的指令中访问控制器的属性 - How can I access attribute of controller in directive from calling controller 如何在角度指令中使用控制器对象的值? - How can i use controller object values in angular directive? 如何在指令链接中访问angular $ scope控制器? - How to access angular $scope controller in directive link? 如何访问从父指令传递但在控制器中定义的子指令中的功能? - How can I access the function in child directive which passed from parent directive but defined in controller? Angular-编译指令后无法访问控制器方法 - Angular - Can't access controller methods after compiling directive 如何从父指令/控制器访问指令范围? - How do I access a directive scope from a parent directive/controller? 如何在Angular中从控制器访问范围到自定义指令? - How to access scope from controller to custom directive in Angular? Angular:如何在控制器中访问元素指令的作用域 - Angular: How to access an element directive's scope in the controller Angular / Ionic:当我更新控制器中的变量时,如何刷新指令? - Angular/Ionic: how can I refresh a directive when I update variables in the controller? 我可以将角度控制器和指令放在单独的 JS 文件中吗? - Can I have the angular controller and the directive in separate JS files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM