<p ng-repeat="row in matrix">
<span ng-repeat="column in row">
<input type="text" style="width: 20px; text-align: center;" ng-model="column" ng-change="{{column = }}">
</span>
</p>
在我的控制器上:
$scope.matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
我有一小段代码,我希望那个小文本输入框与matrix[i][u]
。我知道我可以使用ng-model=
使文本框与某个变量相关联。
但是,我希望它是双向的 - 更改变量将更改文本框值,更改文本框值将更改变量。然而,当我有ng-model
在输入文本框中,我似乎无法编辑其值,因为它总是“重置”为其默认值。
我知道我可以使用ng-change
但我把中间线做了这样的:
<input type="text" style="width: 20px; text-align: center;" ng-model="column" ng-change="update">
并且调用 $scope.update() 函数不起作用。我也仍然无法编辑文本框值。
tl;dr:我怎样才能有一个带有ng-model
并允许编辑它以编辑文本框值和 ng-model 上的变量。