2013-01-10 57 views
0

AngularJs来源:更改值时,为什么嵌套作用域中的模型不会更新?

<html ng-app> 
    <body ng-controller="Controller"> 
    <div ng-init="numbers=[11,22,33]"> 
     <div ng-repeat="n in numbers"> 
     <input type="text" ng-model="n"/> [{{n}}] 
     </div> 
    </div> 
    <script> 
     function Controller($scope) {} 
    </script> 
    </body> 
</html> 

当我更改输入的值,在右边的文本将不会被更新。哪里错了?

的现场演示是在这里:http://jsfiddle.net/Freewind/TZwxy/

可以在输入更改值看看。

回答

1

尝试用对象的数组代替:

function Controller($scope) { 
    $scope.numbers = [{value: 11 }, {value: 22 }, {value: 33 }]; 
} 

<html ng-app> 
    <body ng-controller="Controller"> 
    <div> 
     <div ng-repeat="n in numbers"> 
     <input type="text" ng-model="n.value"/> [{{n.value}}] 
     </div> 
    </div> 
    </body> 

</html> 

参见jsFiddle

相关问题