我想在angularjs中更新关于表达式的文本框的值,请检查此代码
<td><input type="text" ng-model="entry.sale_qty" required style="width: 200px" ></td>
<td><input type="text" ng-model="entry.sale_price" required style="width: 200px"></td>
<td><span> <input type="number" ng-model="entry.sale_amount" required>
{{entry.sale_price*entry.sale_qty|number}}
</span> </td>`
表达式生成的值应该填充到第三个文本框?
答案 0 :(得分:0)
您需要将其分配给另一个范围变量
<input type="number" ng-model="entry.sale_amount = entry.sale_qty * entry.sale_price" required>
答案 1 :(得分:0)
更改您的HTML
<div ng-controller="testController">
<td><input type="text" ng-model="entry.sale_qty" required style="width: 200px" ng-change="updateVal(entry.sale_qty)"></td>
<td><input type="text" ng-model="entry.sale_price" required style="width: 200px" ng-change="updateVal2(entry.sale_price)" ></td>
<td><span> <input type="number" ng-model="entry.sale_amount" required>
{{entry.sale_amount}}
</span> </td>
</div>
并在您的控制器中
function testController($scope) {
$scope.entry={
sale_qty:'',
sale_price:'',
sale_amount:''
};
$scope.updateVal = function(val) {
$scope.entry.sale_amount=val*$scope.entry.sale_price;
};
$scope.updateVal2 = function(val) {
$scope.entry.sale_amount=val*$scope.entry.sale_qty;
};
}