0
編輯:我的工作了,我需要使用[tray.id]代替{{tray.id}}AngularJS:我如何使用對象ID創建一組表單域
我有一組「托盤」,我想構建一個表單來編輯它們,但我不確定如何爲每個托盤設置ng模型,以便我可以區分它們。
這不起作用,角度不喜歡我把{{tray.id}}到NG-模型
<div ng-repeat="tray in formData.trayData">
<div class="form-group">
<label class="control-label" for="formData.trays.{{tray.id}}.name">Name:</label>
<div class="controls">
<input type="text" class="form-control" name="tray.{{tray.id}}.name" ng-model="formData.trays.{{tray.id}}.name" placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="control-label" for="formData.trays.{{tray.id}}.seal">Seal:</label>
<div class="controls">
<input type="text" class="form-control" name="tray.{{tray.id}}.seal" ng-model="formData.trays.{{tray.id}}.sealed" placeholder="Seal">
</div>
</div>
</div>
在我的控制我的設置FORMDATA使用JSON對象從API
$scope.formData.trayData = $scope.surgeryDetails.trays;
$scope.formData.trays = [];
這裏是我從{{formdata.trayData}}得到
[{"id":8,"name":"Tray 1","seal":"Foo","status_id":9},{"id":9,"name":"Tray 2","seal":"Bar","status_id":9}]