如果要$broadcast
使用$rootScope
:
$scope.startScanner = function() {
$rootScope.$broadcast('scanner-started');
}
然后使用$scope
您控制器的接收:
$scope.$on('scanner-started', function(event, args) {
// do what you want to do
});
如果愿意,可以在以下情况下传递参数$broadcast
:
$rootScope.$broadcast('scanner-started', { any: {} });
然后接收它们:
$scope.$on('scanner-started', function(event, args) {
var anyThing = args.any;
// do what you want to do
});