Angular 2 : Chain Observables in Resolver
<p>I am new to Angular2 and observables. I am trying to return the result of a chain of observables to my resolver and couldn't find an answer on SO. Everything works fine when I return only one observable, but fails when those are chained. I've simplified the code to calling consecutively twice the same test function :</p>

<pre><code>@Injectable()
export class SwResolve implements Resolve&lt;any&gt; {
    constructor(private swService: SwService) {}    
        resolve (route: ActivatedRouteSnapshot): Observable&lt;MyObject&gt; | Promise&lt;any&gt; | any {
             this.swService.getTestData().subscribe(data =&gt; {
                 return this.swService.getTestData();
             });
        }
}
</code></pre>

<p>SwComponent :</p>

<pre><code>export class SwComponent implements OnInit {constructor(
    private route: ActivatedRoute,
    private router: Router
  ) { }

  ngOnInit(): void {
    this.route.data.forEach((data: any) =&gt; {
      // Handle data received
     });
  }
};
</code></pre>

<p>SwService :</p>

<pre><code>  getTestData() {
    return Observable.create(observer =&gt; {
      let testObject : SwDataObject = {
        'labels':['value0','value1'],
        'desktop':[123,456],
        'mobile':[789,1011]
      };
      observer.next(testObject);
      observer.complete();
    });
  }
</code></pre>

<p>What am I doing wrong here ?</p>

<p>Thanks !</p>

<p>Edit Jun 17:
Adding some more info, as it took me a while to wrap my head around RxJs' methods (flatMap, mergeMap, ...). The main reason was because I just didn't get the functional aspect of them. I encourage people in the same boat to have a look at <a href="https://medium.com/@cscalfani/so-you-want-to-be-a-functional-programmer-part-1-1f15e387e536" rel="nofollow noreferrer">these excellent series of articles on functional programming</a> by Charles Scalfani.</p>