// Code goes here
angular.module('app', [])
.controller('AController', function($scope, aService) {
$scope.isFinished = false;
$scope.$watch(function(){return aService.isFinished}, function(newVal, oldVal) {
$scope.isFinished = newVal;
});
})
.controller('BController', function($scope, aService, $timeout) {
$scope.load = function(){
$timeout(function() {
aService.isFinished = true; // how to pass extra param meter here?
}, 1000);
}
})
.service('aService', function() {
this.isFinished = false;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.4.3" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="AController">
is finished? : {{isFinished}}
</div>
<div ng-controller="BController">
<button ng-click="load()">load of controller B</button>
</div>
<div ng-controller="CController">
<button ng-click="load()">load of controller C</button>
</div>
</body>
</html>
Above code demonstrate how I use service to talk between controllers. I just pass true if the value been changed in controllers. But now how to pass multiple param instead of just single true or false? so that I can know from which controller the value been changed.