私は次のことをしようとしています:
サービスを介して相互に通信する2つのコントローラーがあります(ここに私のjsFiddleがあります: http://jsfiddle.net/GeorgiAngelov/a9WLr/1/ )。
アイデア:
アイデアは、1 つのコントローラーを変更すると、他のコントローラーのフィールドに反映されるため、ライブアップデート機能が作成されるというものです。ただし、現在の SecondCtrl は 4 つの入力フィールドすべてを同時に更新し、その逆も同様であり、1 つの入力ごとに 4 つすべてを同時に更新します。
私が達成しようとしていること:
私が達成したいことは次のとおりです。コントローラー1の入力フィールドのいずれかをクリックするたびに、コントローラー2の入力ボックスにデータを入力して、コントローラー2が最初にクリックされた入力フィールドを実際に変更できるようにしたい.
HTML
<body ng-app="project">
<div ng-init=" data = [3,4,5,6]">
<h2>{{name}}</h2>
<input ng-model="thing.x"/ ng-repeat="singledata in data" ng-controller="FirstCtrl">
</div>
<div ng-controller="SecondCtrl">
<h2>{{name}}</h2>
<input ng-model="someThing.x"/>
</div>
</body>
JS
var projectModule = angular.module('project',[]);
projectModule.factory('theService', function() {
return {
thing : {
x : 100
}
};
});
function FirstCtrl($scope, theService) {
$scope.thing = theService.thing;
$scope.name = "First Controller";
}
function SecondCtrl($scope, theService) {
$scope.someThing = theService.thing;
$scope.name = "Second Controller!";
}