Hi I’m wondering what is better in terms of performance. Let’s say I have this factory that broadcasts stuff:
angular.module('core.foo')
.factory('Foo',
['$rootScope',
function FooFactory($rootScope) {
$rootScope.$broadcast('bar', baz);
}
]
);
And have a component somewhere (or a lot of them) listening for that event. What would be better?
To use $rootScope.$on:
angular.module('foo').component('foo', {
templateUrl: 'foo.html',
controller: ['$rootScope',
function FooController($rootScope) {
$rootScope.$on('bar', function(event, data){
// use the data
});
}]
});
or $scope.$on:
angular.module('foo').component('foo', {
templateUrl: 'foo.html',
controller: ['$scope',
function FooController($scope) {
$scope.$on('bar', function(event, data){
// use the data
});
}]
});
Both would work, I’m just curious.