【发布时间】:2016-01-07 21:57:37
【问题描述】:
我有一张表格,其中列出了一些带有一些输入的产品,基本上我想要的是在另一个更改时更改输入值,这里是<tr>:
<tr ng-repeat="bought_product in vm.bought_products track by bought_product.id">
<td>
{{ bought_product.name }}
</td>
<td>
<input type="number" class="form-control"
min="1" max="1000" placeholder="#"
ng-model="bought_product.quantity">
</td>
<td>
<div class="input-group">
<span class="input-group-addon">$</span>
<!-- This is the input where I'll insert a price -->
<input type="number" class="form-control no-spin"
min="1" max="1000" placeholder="#" ng-change="vm.calculateVatPrice(bought_product.price)"
ng-model="bought_product.price">
</div>
</td>
<td>
<div class="input-group">
<span class="input-group-addon">$</span>
<!-- This input will automatically be filled -->
<input type="number" class="form-control no-spin"
min="1" max="1000" placeholder="#"
ng-model="bought_product.vat_price">
</div>
</td>
</tr>
【问题讨论】:
-
“当另一个改变时”是什么意思?
-
@ShaohaoLin 当输入 1 的值改变时,计算输入 2 的值
-
您只需将
$scope.bought_product.vat_price更改为$scope.vm.calculateVatPrice(bought_product.price) -
@JohannesJander 不知道你有没有注意到,它在一个
ng-repeat里面,所以bought_product.vat_price不是一个简单的从控制器改变的值
标签: angularjs ng-repeat angular-ngmodel