[英]$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.