Is It good to subscribe to an observable within another subscription handler?

Viewed 4086

I'm using Angular2 and I have a question about what is the best way to do if I have many observables. Can I put subscriptions inside each other or put each one in a different method and put the results in class properties?

Example :

ngOnInit() {
this.route.params**.subscribe**(params => {
   if (params['id']) {
    this.load = true;
     this.batchService.getPagesOfCurrentObject(params['id'], "10", "0")
       **.subscribe**(result => {
         this.stream = result;
         if (this.stream.length > 0) {
           this.stream.forEach(page => { this.batchService.getPageStreamById
           (page.pageId)**.subscribe**(pageStream => {
              let base64 = btoa(new Uint8Array(pageStream.data)
                 .reduce((data, byte) 
                    => data + String.fromCharCode(byte), ''));
               this.pages.push(base64 );

             })

             return;
           });
         }

     },
       error => this.errorService.setError(<any>error),
       () => this.load = false
       );
   }
 });

 try {
   this.customer = this.sharedService.processSelect.subscription.customer;
 } catch (err) {
   return;
 }
}
1 Answers
Related