i was looking how people write code to communicate between two controller. i got one code which is working but not sure the approach is good or standard. so review the code and tell me should we follow the approach to communicate between two controller.
<body ng-app="app">
<div ng-controller="firstCtrl">
controller 1
<select ng-options="item for item in items" ng-model="mdl">
</select>
<button ng-click="updateAlphabets()">update</button>
</div>
<div ng-controller="secondCtrl">
controller 2
<select ng-options="item for item in items" ng-model="mdl">
</select>
<button ng-click="updateItems()">update</button>
</div>
</body>
function firstFunc($scope){
$scope.items=["one","two","three"];
$scope.updateAlphabets=function(){
secondFunc($scope);
$scope.updateItems();
};
}
function secondFunc($scope){
$scope.items=["apple","boy","cat"];
$scope.updateItems=function(){
$scope.items=["a","b","c"];
};
}
angular.module("app",[]).controller("firstCtrl",["$scope",
firstFunc]).controller("secondCtrl",["$scope",
secondFunc]);
looking for suggestion because i am learning angular now and i am after right approach and pattern where majority of people follow. thanks