尝试将单个模型绑定到两个控制器以同时更新。然后使用标记显示模型的相关值。
的index.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body >
<div ng-app="" >
<input type="text" ng-model="model.msg">
<h1>{{model.msg}}</h1>
<div ng-controller="firstController">
<input type="text" ng-model="model.msg">
<h1>{{model.msg}}</h1>
</div>
<div ng-controller="secondController">
<input type="text" ng-model="model.msg">
<h1>{{model.msg}}</h1>
</div>
</div>
<script type="text/javascript" src="controller/main.js"></script>
<script type="text/javascript" src="dependancies/angular.min.js"></script>
</body>
main.js
function firstController($scope){}
function secondController($scope){}
答案 0 :(得分:0)
model.msg
属性绑定到控制器范围。如果要在控制器之间共享数据,请使用Angular Factory / Service