期待どおりにブロードキャストを使用して親コントローラーの$scope
値を子コントローラーの値に更新しようとしていますが、発行関数によって子のe 値を親の値に更新しようとしている間は更新されません。これは私のコードです:$scope
$scop
$scope
app.controller('FirstCtrl', function($rootScope, $scope) {
$scope.firstRegister = function() {
$rootScope.$broadcast('broadcast', $scope.name)
};
$scope.$on('emit', function(events, args) {
$scope.name = args;
});
});
app.controller('SecondCtrl', function($rootScope, $scope) {
$scope.$on('broadcast', function(events, args) {
$scope.name = args;
});
$scope.secondRegister = function() {
$rootScope.$emit('emit', $scope.name)
};
<div ng-controller="FirstCtrl" class="ng-scope">
<input ng-model="name" />
<button ng-click="firstRegister()">Parent</button>
<div ng-controller="SecondCtrl" class="ng-scope">
<input ng-model="name" />
<button ng-click="secondRegister()">Child</button>
</div>
</div>
plnkr リンク : http://plnkr.co/edit/l9qD0ZO4MptnWx6u3U9c?p=preview