我正在尝试执行以下操作:
eventService.emit = function(name, optionalArg1, optionalArg2,... ){
$rootScope.$broadcast(name, optionalArg1, optionalArg2,...);
};
具有无限数量的可选参数。(广播“定义”:$broadcast(string, args...))
我想
eventService.emit =$rootScope.$broadcast;
会起作用,但不起作用($broadcast 函数可以访问 $rootscope 属性)和
eventService.emit = function(){
$rootScope.$broadcast(arguments);
};
似乎不起作用
谢谢您的帮助
原始代码:
services.factory('eventService', function($rootScope, $http){
var eventObject = {};
eventObject.emit = function(name){
$rootScope.$broadcast(name);
};
return eventObject;
});