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.
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.
Comments