I am using AngularJS and I have a directive which has its own Controller. It inherits the scope of the Parent Controller.
As an example, consider the following:
function ParentCtrl() {
$scope.aMethod = function() {
// DO SOMETHING
};
}
function ChildCtrl() {
$scope.bMethod = function() {
// DO SOMETHING ELSE
}
}
Now, $scope.aMethod of ParentCtrl() is triggered by a ng-click directive. What I want to do is call $scope.bMethod of ChildCtrl(). How can I do it?
EDIT: Some more information. The template associated with the ParentCtrl has a button and multiple directives. Each directive loads a form with different sets of inputs. When the button in the ParentCtrl Template is clicked, the directives are loaded one after another by means of ng-switch onand ng-switch-when.
When the user clicks the button, the ChildCtrl which belongs to the directives is meant to store the data in their respective forms.
Thus, when the button is clicked:
1. The ChildCtrl saves the model associated with the current directive that has been loaded.
2. The ParentCtrl loads the next directive in the series.
ng-click is bound to the button which is associated with ParentCtrl. But ChildCtrl also needs to do some action (save the form data) when that button is clicked. How does one accomplish that?
$watchon a parent scope property could accomplish the same thing. Can you provide a skosh more detail on your use case?