1

enter image description herei need to show total amount. first and second text box value sum should be display in total text box. have any way to do it.

    <input type="text" ng-model="add.amount1"/>
<input type="text" ng-model="add.amount2"/>
  Total  <input type="text" ng-model={{add.amount1+add.amount2}}/>
kumara
  • 877
  • 4
  • 19
  • 43

2 Answers2

1

You need to have a ng-change on text boxes and call a function to calculate the sum.

DEMO

var app = angular.module('testApp',[]);
app.controller('testCtrl',function($scope){
$scope.add = {};
$scope.add.amount1 = 0;
$scope.add.amount2 = 0;
$scope.calculateSum = function(){
  $scope.sum = parseInt($scope.add.amount1) + parseInt($scope.add.amount2);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
 <input type="text" ng-change="calculateSum()" ng-model="add.amount1"/>
<input type="text" ng-change="calculateSum()" ng-model="add.amount2"/>
Total  <input type="text" ng-model="sum"/>
</body>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

I hope this can also be considered

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.name = "John Doe";
     $scope.add = {};
      $scope.add.amount1 = 1;
       $scope.add.amount2 = 2;
       $scope.sum = function(add) {
       
      
      return +add.amount1 + +add.amount2;
     }
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app='myApp'>
<div ng-controller='myCtrl'>

<input type="text" ng-model="add.amount1"/>
<input type="text" ng-model="add.amount2"/>
  Total  <input type="text"  value="{{sum(add)}}" />
</div>
 
</body>
</html>
G_S
  • 7,068
  • 2
  • 21
  • 51