2015-07-22 74 views
-5

試圖將單個模型綁定到兩個控制器以同時更新。然後使用標籤顯示模型的相關值。模型未綁定angularjs控制器

的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){} 
+2

Err。所以,*你的問題*? – Manhattan

回答

0

model.msg屬性綁定到控制器範圍。如果您想在控制器之間共享數據,請使用Angular Factory/Service