Call method in directive controller from other controller

后端 未结 4 1810
轮回少年
轮回少年 2020-12-02 03:28

I have a directive that has its own controller. See the below code:

var popdown = angular.module(\'xModules\',[]);

popdown.directive(\'popdown\', function (         


        
4条回答
  •  一整个雨季
    2020-12-02 04:11

    You could also expose the directive's controller to the parent scope, like ngForm with name attribute does: http://docs.angularjs.org/api/ng.directive:ngForm

    Here you could find a very basic example how it could be achieved http://plnkr.co/edit/Ps8OXrfpnePFvvdFgYJf?p=preview

    In this example I have myDirective with dedicated controller with $clear method (sort of very simple public API for the directive). I can publish this controller to the parent scope and use call this method outside the directive.

提交回复
热议问题