I am using $broadcast and $emit in my angularjs application. Here is the code i am registering $emit function :
this.scope.$emit('changeTime', {
currentTime: this.currentTime
});
In another controller i am listening this emit function for returning is object like :
this.scope.$on('changeTime', (event, args) => {
console.log(args.currentTime);
});
Here is all working fine. But this listener is calling in my different function which is called according to different condition :
this.functionone(){
this.scope.$on('changeTime', (event, args) => {
console.log(args.currentTime);
});
}
this.functiontwo(){
this.scope.$on('changeTime', (event, args) => {
console.log(args.currentTime);
});
}
When i call first function current time printed in console. When my condition is changes and calling another function functiontwo() in that time i can also see the functionone console value.
Meaning changetime listener calling two times when second function get call after one.
So how can i unregister this earlier called changetime. So second time its not come.