ページ内の 2 つの場所で 1 つのコントローラーのデータを共有したいと考えています。例えば:
<div ng-app="myApp">
<div ng-controller="myController">
<input type="text" ng-model="x" /> {{x}}
</div>
</div>
<!-- these are in totally different places and I do not want, nor can't nest them -->
<div ng-app="myApp">
<div ng-controller="myController">
<input type="text" ng-model="x" /> {{x}}
</div>
</div>
そしてもちろん、これ:
var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope) {
$scope.x = 'test';
});
最初の入力テキストが何を入力しても、2 番目の入力テキストに反映されるようにするにはどうすればよいですか? およびその逆?データの 1 つのコピーを維持しながら、基本的に同じデータがこれら 2 つのセクションに伝播されます。
JSFiddle はこちら: http://jsfiddle.net/LETAd/
PS: これに関連性がある場合は、手動でブートストラップします。
ありがとう!