Is it possible to use $broadcast and $on/$emit to share a function in a component that exists inside its controller to a totally different controller under different component (see pic above)?. I have tried different examples from google, not sure what i am doing wrong . this is the function (inside the administration component in the picture ):
refreshMarkers = (newMarkerSet) => {
this.leafletData.getMap(this.mapId).then((map) => {
if(this.previousLayer != null){
this.$log.debug('removing map layer %o and adding %o', this.previousLayer, newMarkerSet);
map.removeLayer(this.previousLayer);
map.addLayer(newMarkerSet);
this.previousLayer = newMarkerSet;
}
});
};
inside a different controller which is inside a totaly different component (map-setting.controller.js in the picture ) i want to use that function like this:
deleteAllZones = () => {
let message = this.$filter('translate')('SI-MESSAGES.DELZONE-MSG');
let title = this.$filter('translate')('SUBHEADER.DELZONE-TITLE');
let button = this.$filter('translate')('BUTTON.DELETE');
this.siAlertDialog.confirm(message, title, button).then(() => {
this.deleteAllMapZones();
this.refreshMarkers(); /////like this
})
};
everything is written in es6 and controllers are wraped in class and use a constructor . In case this matters
administration controller i am saying
this.$rootScope.$on('refreshmap'),()=>{
this.refreshmap()
}
and in map-setting.controller.js
notifyMap = () =>{
this.$rootScope.$broadcast('refreshmap')
}
function originally is in administration (ps. look at the picture)