我在 AngularJS 中使用 emit 函数,想知道是否可以将函数作为参数传递。
父 Controller :
$scope.$on("getChildFunction", function(event, func) {
console.log("function is...", func);
})
子 Controller :
$scope.$emit("getChildFunction", $scope.load_function());
但是,当我使用网络检查器时,func 根本没有返回。是否可以使用 emit 将函数向上传递到父作用域?
最佳答案
如果要传递函数本身,省略括号:
$scope.$emit("getChildFunction", $scope.load_function);
如果包含括号 - 您将执行函数并传递函数的结果。
关于javascript - 如何在 AngularJS Emit 中将函数作为参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31928535/