Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

607
Views
RxJS - Tell observable to wait for other observable to emit non null value

I've got this setter which assigns a class member observable systemAreasOptions$. I do it there because it needs to wait for mappedItem$ to have had an emission which is not null. I originially had systemAreasOptions$ assigned at the class level, but it did not wait for mappedItem$. For some reason I couldn't even get the HTML to rerender when using the asyncPipe. How do I tell an observable (systemAreasOptions$ to wait for another observable (mappedItem$), instead of just assigning it where the other one emits?

public set mappedItem(mappedItem: IPermissionsMappedItem) {
    mappedItem.hydrate$Permissions().then(_ => {
        this.mappedItem$.next(mappedItem);
        this.systemAreasOptions$ = from(
            this.lookupService.SYSTEM_AREAS.toNestedLookup()
                .$promise as unknown as Observable<IPermissmissionsLookup[]>
        ).pipe(
            map(systemAreas => orderBy(systemAreas,systemArea => systemArea?.label?.toLowerCase())),
            map(systemAreas => systemAreas.map(area => ({
                ...area,
                permissions: this.getPermissionsForArea(area.id)
            }))),
            shareReplay(1),
            tap(console.log)
        );

        this._subscriptions.add(
            this.systemAreasOptions$.subscribe(
                this.systemAreasOptionsBehaviourSubject$)
        );
    });
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can combine the observables:

  • Create an observable that only emits mappedItems that aren't null
  • Emit both values only when it emits

I beleave you are looking for withLatestFrom:

higherOrder$ = mappedItemThatIsNotNull$.pipe(
  withLatestFrom(systemAreasOptions$)
) 

In your template:

higherOrder$ | async

This will yield [mappedItem, systemAreaOptions]

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!