Currently, I am utilizing the MEAN stack in my application with AngularJS as the frontend. I have a question regarding how to use ng-bind
to display the total sum of a value in another input
in AngularJS. In my scenario, I have a table where I'm using a filter to calculate the total sum for the Sprice
column, resulting in a total sum of 250
. The desired outcome is to bind this total sum value to another input field using ng-model
. For example, if the total sum for sprice
is 250
, then the expected answer for the bound value should also be 250
. You can view the code on my Plunker here. I am unsure about where I might have made a mistake, so any assistance would be greatly appreciated.
In our table setup, we are utilizing a filter to calculate the total sum value for
sprice
. By using
, we were able to obtain the sum of 250.<td>{{resultValue | sumOfValue:'sprice'}}</td>
The goal is to bind this total sum of
sprice
to anotherng-module
input namedsprice_total
, with the expected result being250
.I have provided a reference Plunker here. If anyone knows a solution, please do help us out.
Snippet from My controller: Filter for sprice totalsum calculation:
.filter('sumOfValue', function () {
return function (data, key) {
debugger;
if (angular.isUndefined(data) && angular.isUndefined(key))
return 0;
var sum = 0;
angular.forEach(data,function(v,k){
if(v.confirm=='cancelled'){
sum = sum + parseFloat(v[key]);
}
});
return sum.toFixed(2);
}
})
HTML snippet:
<tr ng-repeat="ram in resultValue=(order.orderfood) | filter: {confirm: '!cancelled'}">
<td>{{$index + 1}}</td>
<td>{{ram.sprice }}</td>
</tr>
<tr>
<td>sum</td>
<td>{{resultValue | sumOfValue:'sprice'}}</td>
</tr>
I attempted to utilize ng-bind
to transfer the sum to another input like so:
<input type="text" ng-model="sprice_total" ng-bind="sprice_total={{resultValue | sumOfValue:'sprice'}}">
- Please ensure to update the Plunker to reflect any solutions provided. Thank you for your assistance.