0

So in my ngOnInit, I have the following

    this._store.select(AuthorSegmentsState.getAuthorSegments).pipe(take(1)).subscribe(res => {
      this.selectedSegment = res.selectedSegment;
      if(!this.selectedSegment.segmentID) {
        this._acm.getSpecificSegment(res.selectedSegment.segmentName).subscribe(segment => {
          this.selectedSegment.segmentID = segment.data.segmentID;
        })
      }
    });

I have heard a few times before that you should never have an observable nested inside another one though.

Is there a more elegant way that I can create this behavior?

  • Also have a look at RxJS `EMPTY` constant that you can return into `mergeMap`, `concatMap`, etc to do nothing. – martin Jun 18 '21 at 11:59

0 Answers0