Reputation: 607
Values is list of obervables over input fields
var example = combineLatest(values);
How do I find sum of values in text field.
example.subscribe(val => {
console.log('Sum:', val);
});
Having subscriber over it gives me output of the form
Sum: (2) ["1", "2"]
Piping over combineLatest gives me NaN
.pipe(reduce((acc, one) => {
var a =Number(acc) + Number(one);
console.log(a);
return a;
}, 0));
Upvotes: 0
Views: 824
Reputation: 14099
You don't have to reduce the Observable, you have to reduce the array it emits.
var example = combineLatest(values).pipe(
map(array => array.reduce((pv, cv) => pv + Number(cv), 0))
);
Upvotes: 3