2016-09-30 24 views
1

林具有如下:

$rootScope.$on('setmoney',function (thisdata) { 

      console.log("setting money"); 
      console.log("money is : " + thisdata); 
}); 

而这别的地方:

$rootScope.$broadcast('setmoney', {cash: 100000}); 

我怎样才能确保我可以取回参数现金setmoney rootcope.on函数? thisdata后

输出:

Object {name: "setmoney", targetScope: Scope, defaultPrevented: false, currentScope: Scope} 
currentScope 
: 
null 
defaultPrevented 
: 
false 
name 
: 
"setmoney" 
preventDefault 
: 
() 
targetScope 
: 
Scope 
__proto__ 
: 
Object 

回答

4

的第一个参数是$on得到的是事件本身。在第一个参数之后,您将得到与事件一起传递的其余参数。

$rootScope.$on('setmoney',function (event, thisdata) { // You forgot to pass the 'event' parameter before the rest of parameters 
    console.log("setting money"); 
    console.log("money is : " + thisdata); 
}); 
+0

救了我从头痛..谢谢很多家伙 –