有一个简单的example ,我想要实现的是,当文本字段更改时,两个模型都应该更改。这可能不使用 $watch 吗?
最佳答案
你只需要让对象通过引用传递而不是传递字符串值..
查看此解决方案
http://codepen.io/anon/pen/Dczmp
<div ng-controller="first">
<input type="text" ng-model="testModel.test_var" />
<p>{{testModel.test_var}}</p>
</div>
<div ng-controller="second">
<p>{{testModel.test_var}}</p>
</div>
在你的 Controller 中:
$scope.testModel = Data
代替
$scope.testModel = Data.test_var
关于javascript - Angularjs - 将服务数据绑定(bind)到许多 Controller 中的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16232180/