We are trying to develop an app using phonegap onsen and angularJS.
I am trying to call a function from a different controllers. I have seen alot of documentation on how to do this like this
But for certain reason it doesn't work for me. Here is my code so far.
module.run(function ($rootScope) {
$rootScope.$on('some-event-here', function (event, data) {
console.log('1');
$rootScope.$emit('show-dialog-of-some-event', data);
//I also tried
//$rootScope.$broadcast('show-dialog-of-some-event', data);
});
});
module.controller('controller1', ['$scope', '$http', function($scope, $http) {
$scope.proceed = function() {
console.log('0');
$scope.$emit('some-event-here', {});
}
}]);
module.controller('controller2', ['$scope', '$http', function($scope, $http) {
$scope.$on('show-dialog-of-some-event', function (event, data) {
console.log('2');
ons.createDialog('some-dialog.html').then(function(dialog) {
//some code here
});
});
}]);
It show on the console '0' and '1' but it doesn't show '2'.
This could be an easy problem but I can't seem to find the problem with my code.
Thanks in advance.
If you are communicating between sibling controllers and from parent controller to child controller you have to use $scope.$broadcast but If you want to communication from child to parent you have to use $scope.$emit