如何从angularjs中的另一个控制器调用函数

2025-01-07 05:22:07
推荐回答(1个)
回答1:

app.controller('One',['$ scope','$ rootScope'
function($ scope){
$ rootScope。$ on(“CallParentMethod”,function(){
$ scope.parentmethod();
});

$ scope.parentmethod = function(){
// task
}
}
]);
app.controller('two',['$ scope','$ rootScope'
function($ scope){
$ scope.childmethod = function(){
$ rootScope。$ emit(“CallParentMethod”,{});
}
}
]);