Angularjs ng-value sum fields -


hi have inputs this

<input type="text" ng-model="tbl.public"> <input type="text" ng-model="tbl.private"> <input type="text" ng-value="tbl.public--tbl.private" ng-model="tbl.total"> 

the above form working fine sum public , private value , put in tbl.total field. problem in edit form value of tbl.total, tbl.public, tbl.private assign database.

js

$scope.tbl.public=10; $scope.tbl.private=25; $scope.tbl.total=35; 

now after assigning value js when change value of tbl.public or tbl.private in form not affecting tbl.total should sum 2 value , put in tbl.total field. thank , suggestion.

ng-value used on radiobuttons , option elements, it's not fit use case.

a better thing implementing updatetotal() function combined ng-change. recommend changing input types number you're not allowing users sum text.

<input type="number" ng-model="tbl.public" ng-change="updatetotal();"> <input type="number" ng-model="tbl.private" ng-change="updatetotal();"> <input type="number" ng-model="tbl.total"> 

in controller:

$scope.updatetotal = function() {   $scope.tbl.total = $scope.tbl.public + $scope.tbl.private; } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -