![](/img/trans.png)
[英]$scope variable inside the function is not getting updated in angular js
[英]Angular JS broadcast not getting inside child scope
請參考-http://jsfiddle.net/U3pVM/18701/
在控制台中,我只看到“ outer1”正在記錄,內部作用域未記錄。 缺少什么嗎?
var app = angular.module("myapp", []);
app.controller("outer1", function($scope) {
$scope.$on("newmessage", function() {
console.log("outer1");
});
$scope.$broadcast("newmessage");
});
這是一個定時問題-孩子們在父母已經解雇了$ broadcast之后進行初始化。 如果您使用$timeout
延遲$broadcast
,則子代將收到事件( update fiddle ):
app.controller("outer1", function($scope, $timeout) {
$scope.$on("newmessage", function() {
console.log("outer1");
});
$timeout(function() { // delay $broadcast using $timeout
$scope.$broadcast("newmessage");
}, 0);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.