Let's say I have two pages, page A and page B, which have controller A and controller B, respectively. I go to page A first, and do an operation, which would call $broadcast to send out one object:
$rootScope.$broadcast('payData', obj)
I want to receive this broadcast in controller B. But since I have not gone to page B, the constructor of controller B is not initialized. Since I try to receive this message in the constructor of controller B, it never receives the message.
export default class ControllerB{
constructor($scope, $rootScope){
this.scope = $scope;
this.rootScope = $rootScope
$rootScope.$on('payData', (event, obj) => {
console.log('broadcastPayData receive obj:', obj);
})
}
//some other cool staff
}
Any idea how to solve this? Thanks.