2017-03-28 50 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! 
}); 
相關問題