我試圖讓ng-repeat在收據中重複項目列表,spiffs。我有這個工作的編輯功能,但我不能得到添加頁面的工作,因爲它讀取:TypeError:無法讀取ng-repeat的undefined屬性
TypeError: Cannot read property 'spiffs' of undefined
這裏是代碼導致它:
$scope.model.spiffs = [];
$scope.model.spiffs = [{ spiff_id: 0, receipt_id: 0, product_id: 0, spiff_amt:0, quantity: 1, active: true, note: null }];
起初是第二但我想我會試着讓$ scope.model是一個空數組來嘗試提前聲明數組,我嘗試了不同的變體,我想我只是缺少一些簡單的東西。當我沒有任何初始輸入來填充表單時,我需要做什麼才能將表單設置爲ng - 重複一組字段?之後,我可以通過簡單的$scope.model
調用獲取所有表單數據並將其發送到我的API?
這裏是希望將要實現HTML:
<div class="col-xs-10 col-xs-offset-2" ng-repeat="item in model.spiffs">
<div ng-hide="item.active === false">
<div class="col-xs-4 form-group">
<select name="productID" ng-model="item.product_id" required="" ng-change="changeSpiffProduct($index)" class="form-control"
ng-options="product.product_id as product.model_number + ' ' + product.name for product in products">
</select>
</div>
<div class="col-xs-2 form-group">
<input name="spiff_sale_price" type="text" placeholder="" ng-model="item.quantity" class="form-control input-md">
</div>
<div class="col-xs-2 form-group">
<p name="spiff_amt" class="form-control-static">{{item.spiff_amt | currency: "$"}}</p>
</div>
<div class="col-xs-2 form-group">
<p name="spiff_total" class="form-control-static">{{item.spiff_amt * item.quantity | currency: "$"}}</p>
</div>
<div class="col-xs-2 form-group">
<button class="btn btn-danger" novalidate ng-click="removeSpiff($index)"><i class="fa fa-minus"></i></button>
</div>
</div>
</div>
非常感謝您預先的幫助!
我們需要看看你的控制器和'$ scope.model.spiffs'來自哪裏,給你適當的建議。 – martin
它假設顯示TypeError:無法設置未定義屬性'spiffs' – Siva