简体   繁体   中英

How to communicate between two controller in my case?

I am trying to communicate between two controllers in my case

I have something like

html

<div ng-controller='testCtrl'>
    <div ng-click='clickBtn()'>clikc me</div>
</div>

..other contents...

<div ng-controller='testTwoCtrl'>
    other contents...
</div>

JS

  app.controller('testCtrl', function($scope) {
        $scope.clickBtn = function(){
            alert('hey')
        }
    }

    app.controller('testTwoCtrl', function($scope) {
        //is there anyway to know if clickBtn method is called from here?
    }

I was hoping to know if there is a way to notify testTwoCtrl if the button is clicked. Thanks for the help!

You can create a parameter for the clickBtn function.

I would suggest creating a boolean parameter and then if clickBtn is called from testTwoCtrl pass a value of true otherwise you can leave it blank in which case it will be false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM