FlyingCat
FlyingCat

Reputation: 14290

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!

Upvotes: 0

Views: 50

Answers (1)

Adjit
Adjit

Reputation: 10305

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.

Upvotes: 1

Related Questions