I have dynamic form fields like this:
<div ng-repeat="wspStaffTbl in staff_codes">
{{wspStaffTbl.Staff_Type}}
<input type="text" ng-model="wspStaffTbl.Permanent" ng-change="updateTotal()">
<input type="text" ng-model="wspStaffTbl.Contract" ng-change="updateTotal()">
<input type="text" ng-model="wspStaffTbl.Total">
</div>
Where staff_codes are recived by my database. I want to sum each Permanent and Contract and put it in Total whenever user put value in wspStaffTbl.Permanent or wspStaffTbl.Contract.
I tried this
<input type="text" ng-value="(wspStaffTbl.Permanent)--(wspStaffTbl.Contract)" ng-model="wspStaffTbl.Total">
It working fine but if the fields already have some data (eg. in edit form) it won't update total. So I need this in my controller:
$scope.updateTotal= function(){
$scope.wspStaffTbl.Total = $scope.wspStaffTbl.Permanent + $scope.wspStaffTbl.Contract;
}