Я новичок в AngularJS, и у меня есть проблема с простой системой счетов, которую я пытаюсь создать. Проблема заключается в том, что поле ввода, которое показывает стоимость продукта (ng-model: item.cost), не заполняется значением в зависимости от выбора, который я делаю в поле выбора.Поле ввода углового ввода, не отображающее значение ng-модели
HTML-:
<div ng-controller="CartForm">
<table class="table">
<tr>
<th>Description</th>
<th>Qty</th>
<th>Cost</th>
<th>Total</th>
<th></th>
</tr>
<tr ng-repeat="item in invoice.items" ng-controller="ProductController as productCtrl">
<td><select ng-model="selectedItem" ng-options="product.name for product in productCtrl.products">
</select></td>
<td><input type="number" ng-model="item.qty" ng-required class="input-mini"></td>
<td><input ng-model="item.cost" value="{{selectedItem.price}}"></td>
<td>€{{item.qty * selectedItem.price}}</td>
<td>
[<a href ng-click="removeItem($index)">X</a>]
</td>
</tr>
<tr>
<td><a href ng-click="addItem()" class="btn btn-small">add item</a></td>
<td></td>
<td>Total:</td>
<td>€{{total()}}</td>
</tr>
</table>
</div>
В app.js:
app.controller('CartForm',function($scope) {
$scope.invoice = {
items: []
};
$scope.addItem = function() {
$scope.invoice.items.push({
qty: 1,
description: '',
cost: 0
});
},
$scope.removeItem = function(index) {
$scope.invoice.items.splice(index, 1);
},
$scope.total = function() {
var total = 0;
angular.forEach($scope.invoice.items, function(item) {
total += item.qty * item.cost;
})
return total;
}
});
вы можете воспроизвести проблему в Скрипки/Plunker? –
Вы хотите, чтобы загрузка «ng-model» была в 1-й раз или при каждом нажатии? –