我希望能夠根據其他兩個字段的結果更新我的數據模型中的值。使用基於其他字段之和的angularjs更新模型
<td><input ng-value="s.hours*s.rate"></td>
我沒有問題的計算結果,但我怎麼能夠綁定它toal?
如我試圖
<td><input ng-model="s.total" ng-value="s.hours*s.rate"></td>
但該模型在這裏覆蓋了價值?
查看完整的例子
'use strict';
var app = angular.module('app', []);
app.controller('MainCtrl', ['$scope', function ($scope) {
$scope.staff = [
{"id": "1","name": "Alex","rate": "10", "hours": "10","total":"0"},
{"id": "2","name": "Brad","rate": "20", "hours": "10","total":"0"},
{"id": "3","name": "Cam","rate": "15", "hours": "10","total":"0"}
];
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="MainCtrl">
<table>
<tr><td>name</td><td>rates</td><td>hours</td><td>total</td><td>total</td></tr>
<tr ng-repeat="s in staff">
<td>{{s.name}}</td>
<td><input ng-model="s.rate"></td>
<td><input ng-model="s.hours"></td>
<td><input ng-value="s.hours*s.rate"></td>
<td><input ng-model="s.total"></td>
</tr>
</table>
</div>
</div>
怎麼可以這樣來達到的?
有幾種方法可以使用angular,使用'ng-change'或'$ watch' – charlietfl 2015-02-23 19:49:13