Closed mattsyp closed 7 years ago
When you load it from scope, the value is an integer. But when you edit it from textbox, the value is converted to string. You need to parse it to integer to make the sum.
Hi fikoborquez,
I understand what is happening, but I don't understand why the sum function works like this. I can't see any reason a sum function wouldn't parse the object array as a numeric type. Is there a work around for this issue? Can I parse the array inline, or should I just write my own sum method?
Thanks
You can simply fix like this:
Number
function to your scope. $scope.number = Number
{{ list | map: 'myValue' | map: number | sum }}
I'm gonna close this, but feel free to open it if you still have issue with it.
I have been using this library for a little and found an issue when using sum on forms. I have created a plunker so you can see it. What happens is, initially it calculates the proper sum, but when you change any of the text fields, instead of summing, it concatenates the values.
https://plnkr.co/edit/w85BPYsl5qBVjs4CBXzb
To test, load the plunker and change any of the values in the form and you will see the sum go from being correct to incorrect. There is no validation on the text fields so it would be as simple as I could make it.