John Higgins John Higgins - 3 months ago 19
AngularJS Question

Totalling Calculated fields with AngularJS

I have the following AngularJS code and I want to be able to total the calculated fields that appear in the results1 and results2 disabled inputs. Can someone advise how this is done?

Thanks,

John

<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>

<script type="text/javascript">

</script>

</head>
<body>

<form name="form" action="index.php" method="post" autocomplete="off">

<input type="text" name="field1" ng-model="field1" ng-init="field1='10'">

<input type="text" name="field2" ng-model="field2" ng-init="field2='10'">

<br>

<input type="text" name="results1" value="{{(+field1*100|currency)}}" disabled>

<input type="text" name="results2" value="{{(+field2*100|currency)}}" disabled>

</form>

<h1>{{(+results1--results2|currency:"")}}</h1>

</body>
</html>

Answer
 <h1>{{(+field1--field2|currency:"")}}</h1>
 <h1>{{(+field1*100--field2*100|currency:"")}}</h1>

Can you try like this ?

Comments