a8m / angular-filter

Bunch of useful filters for AngularJS (with no external dependencies!)
https://github.com/a8m/angular-filter
MIT License
2.93k stars 332 forks source link

Issue with sum when using filter and map #253

Closed mattsyp closed 7 years ago

mattsyp commented 7 years ago

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.

fikoborquez commented 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.

mattsyp commented 7 years ago

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

a8m commented 7 years ago

You can simply fix like this:

I'm gonna close this, but feel free to open it if you still have issue with it.