I want to send an event to another controller.
To do this, I already know way using $rootScope.$broadcast
or $scope.$emit
then listen event using $scope.$on
.
It is a general way, but my project initiates the controller in a different JS file.
//In broadcaster.js
function broadcasterCtrl(~~~~~, broadcasterService){
~~~~~~~~~~
}
function broadcasterService(~~~~~){
~~~~~~~~~~
}
angular
.module('myApp')
.service('broadcasterService', broadcasterService)
.controller('broadcasterCtrl', broadcasterCtrl);
//In listener.js
function listenerCtrl(~~~~~, listenerService){
~~~~~~~~~~
}
function listenerService(~~~~~){
~~~~~~~~~~
}
angular
.module('myApp')
.service('listenerService', listenerService)
.controller('listenerCtrl', listenerCtrl);
Because of this structure, the listener controller is initiated when the view(state) is called. So I used $window.localStorage.setItem('key', value)
, but I don't like it because, I think, it is very vulnerable.
Is there any idea using $broadcast
? or is it secure using localStorage?