0
votes

So, I am using ngrx store for getting data. Once I select the property I want from the store, after then I subscribed it to get observable stream. My data contains array of object. So in this array of objects, I have to do some modifications in some properties of each objects.

So for that I converted my array of objects into sequential observable by using 'from()' operator of rxjs library and then assign this into new Observable object. With this new Observable object, I applied map function for doing modification and at the end again returned a new Observable object. Till this step everything is working fine. Problem occurs, when I am subscribing to this new modified observable object it is emitting values sequentially not the whole array of objects. But I want modified array of objects.

this.statusObj = this.store.select(s => s.userStore.data);
this.statusObj.subscribe(rslt => {
    this.usrArr = rslt;
})

this.newstatusObj = from(this.usrArr);
this.newstatusObj2 = this.newstatusObj
    .pipe(map(() => {
        //////some modifications
        return
    }))

this.newstatusObj2.subscribe(val => {
    console.log(val);  //this line is emitting sequential values..but i want array of objects
})
1
What is the value of usrArr?Robert garcia

1 Answers

1
votes

You do not need to use .from(), that will convert your data to multiple emissions based on your array. Since your store already gives you an observable which contains your data to modify, simply use .map() to modify them, like this:

this.store.select(s => s.userStore.data)
    .pipe(map((rslt)=>{
        //DO YOUR MODIFICATION HERE.
    }))
    .subscribe(val=>{
        console.log(val) // now your data is in array of objects
    })