子控制器尚未实例化。包裹broadcast在一个timeout作品:http://plnkr.co/edit/MF7P16K1OTv46JNgkkih?p=preview
$timeout(function { $scope.$broadcast('someEvent', 'bidule'); });解决方法
我试图通过$ scope。$
on和$ scope。$
broadcast在两个控制器之间共享信息。
这是视图:
<div ng-controller="ParentCtrl"> <div ng-controller="ChildCtrl"> {{content}} </div> </div>
和控制器:
.controller('ParentCtrl',['$scope',function($scope) { $scope.$broadcast('someEvent','bidule'); }]) .controller('ChildCtrl',function($scope) { $scope.$on('someEvent',function(event,b) { $scope.content = b; }); }])
和矮人
我在这里做错了什么?
评论列表