0

i will start by adding the code, result i get and in the end what i would like to obtain and if it is possible.

The result which i'm getting is Array[object, object, ...] where object is Array

export class SomeService {
           ....
           .... 
     public someFunction(): MyObject[]{
         Observable
            .forkJoin(this.userItemsA(userId), this.userItemsB(userId), etc)
             .filter(each => {
                      for (let array of each) {
                            let x: any = <any> array;
                               return x.length > 0;
                            }
                        })
             .map(result => {
                   return result;
              })
            .subscribe(result => {
                  /// what i would like to do for example assuming only 1st array has items
                  /// do something here with result[0] 
                  /// return MyObject[] from result[0]
        });
    ....
    }
}

Filter structure

filter structure

I'm in my early learning stage of angular2 and reactive programming, what i would like is to filter so that the map result will be only the arrays that have at least 1 item.

Thank you

2
  • 1
    What's the structure of your data in .filter(each => ...? Commented Nov 7, 2016 at 12:16
  • i've uploaded the structure of the filter, thx Commented Nov 7, 2016 at 12:24

2 Answers 2

1

Instead of .filter use .map

.map(each => {
    return each.filter(array => array.length > 0)
}
Sign up to request clarification or add additional context in comments.

Comments

1

Unfortunately this doesn't work with forkJoin. What it does it joins several Observables into single Observable, thus if any of them is filtered out, the entire joined Observable get's interrupted/filtered.

As @Martin stated, you have to do your filtering in the map branch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.