0

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>
1
  • 1
    {{(+field1*100)-(-field2*100)|currency:"")}} you need to use the model not the name of the element Commented Sep 2, 2016 at 14:12

2 Answers 2

2

Use ng-value instead of value to get that expression evaluated properly

Sign up to request clarification or add additional context in comments.

1 Comment

I changed value to ng-value in results1 and2 and it then did not display the calculated fields.
1
 <h1>{{(+field1--field2|currency:"")}}</h1>
 <h1>{{(+field1*100--field2*100|currency:"")}}</h1>

Can you try like this ?

2 Comments

Thats adds up the value of 10 and 10 in the fields. I want it to total up the calculated fields that are displayed in results1 and results2
then you can use like this. <h1>{{(+field1*100--field2*100|currency:"")}}</h1> You can not get value by name in AngularJS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.