在广播事件之前没有设置广播监听器时,有人可以给我一些关于如何处理这种情况的提示吗?
我已经看到了一些$timeout的解决方案,但他们感觉还不错.谢谢!
var app = angular.module('app',[]); app.controller('ParentCtrl',function ParentCtrl ($scope) { this.data = 'parent'; $scope.$broadcast('parent','Some data'); // event is sent before any listeners are set }); app.controller('ChildCtrl',function SiblingOneCtrl ($scope) { this.data = 'child'; $scope.$on('parent',function (event,data) { document.write(data); // never activates }); });