這將是一個有點棘手的樣本,但它仍然是可能的。您將需要兩個ngRepeat
迴路很少ngInit
/ngChange
操作,以初始化和更新的東西:
angular.module('demo', []).controller('DemoController', Ctrl);
function Ctrl($scope) {
$scope.group = {
name: "test1",
xdata: ["1;2;3", "abhsad"]
}
}
<script src="//code.angularjs.org/1.5.5/angular.min.js"></script>
<div ng-app="demo" ng-controller="DemoController">
<div ng-repeat="(i, val) in group.xdata track by $index"
ng-init="parts = val.split(';')">
<input type="text"
ng-model="part"
ng-repeat="(j, part) in parts track by $index"
ng-change="parts[j] = part; group.xdata[i] = parts.join(';')">
</div>
<pre>group = {{group | json}}</pre>
</div>
ngChange,完美!奇蹟般有效。 –