2017-03-28 53 views
0

我有一个控制器1a函数返回对象的数组,调用另一个控制器Angulrjs

而且在控制器2,我必须在我创建列表循环,所以我认为这会工作。

$rootScope.$emit("CallParentMethod").forEach(function(row) 

     { 
      console.log(row.key); 

     }); 

但我越来越没有我期待的一样格式的console.log我看到了对象,我得到的控制器2 对象,就像是

{name: "CallParentMethod", targetScope: l, defaultPrevented: false, currentScope: null} 

那么我怎么能循环到一个对象,我从另一个控制器。在其他控制器然后

function letSomethingHappen() { 
    $rootScope.$broadcast("CallParentMethod", { 
     title: "Let's pass this string!" 
    }); 
} 

回答

1

你可以通过对象的事件

$rootScope.$on("CallParentMethod", function(event, passedArgs) { 
    console.log(passedArgs.title); // Let's pass this string! 
}); 
相关问题