Angular, RxJs - dynamic new observable with user reaction as resolve

aboutus

We are creating a messenger module, what needs to be RxJs based and need to emit a value based on user reaction to another component.

I've tried with of(), passing existing BehaviorSubject, but none of them was worked as expected. The functionality should be like a simple promise what the user could resolve.

Some protocode to show the idea:

MessageService {
  message = new BehaviorSubject(undefined);

  addMessage(message) {
    this.message.next(message);
    return new Subject();
  }

  userClick(boolean) {
  // clicked on Ok or Cancel
  // We want to send that value to the subscription on addMessage
  }

}

AnotherService {
  ....
  this.messageService.addMessage('Are you sure?')
      .subscribe(boolean => console.log(boolean));
  ....
}

So when the user click on the Ok or Cancel button in what handled in the MessageService, the subscription at the AnotherService should receive the answer.

Sergey

To perform that you need somewhere to have an Observable created as well as method which will pass true/false for example.

This could be done by

requestUser(): Observable<boolean> {
// do some actions

return new Observable(observer => {
  // react here on what user does
  observer.next(true);
})
}

what will cause the subscriber to get true/false on subscribe.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular, rxjs: HTTP Observable depending authenticated user

Angular RxJS add data from new observable to current observable

How can I subscribe or merge new Observable in RXJS and Angular

Angular 4 RxJs Observable Subjects array not updating with new object

Angular & RXJS - [ts] Property 'map' does not exist on type 'Observable<User>'

Angular / RxJS Multicasting Observable of Observable

Angular/RxJS: synchronous observable

RXJS/Angular Replace Observable

RxJS Observable merge angular

Angular execute resolve with observable

RXJS Observable, with a dynamic function pipe

Merging a new rxjs observable into existing subscribed observable

Is there a way to resolve the inner promise of this rxjs observable?

Angular - RxJS - Observable and method return

subscribe keys of and observable in Angular/RxJS

Angular RxJS Observable loading error

Angular rxjs mix observable and promises

Returning a Property from Observable as Observable in Rxjs Angular

How do I resolve an Observable inside of another Observable? - rxjs

angular resolve with nested promise and observable

Angular 2 router resolve with Observable

Angular 6 + RxJS 6.0 : How to push new element to array contained by Observable

Return observable bit first get new token in Angular 11 / RxJS 7

what is the difference between "new Observable()" and "of()" in RxJs

RXJS, add new key:value to nested observable

Show a nickname on new line after a user add reaction

RxJs: How to combine two observable into a new observable with different type

how to create a new observable subscription based on existing observable in rxjs?

Module not found: Error: Can't resolve 'rxjs/add/observable/throw'