javascript - how to present a pop-up message based on Observable property? -


i have pop-up message want present when observable delivered, string observable.

this function returns string observable:

public sendupdate() {  this._mtservice.sendcurrentupdate(this.mylist).subscribe(  res => this.messagetodisplay = res,  error => this.messagetodisplay = error  );  } 

this function present pop relevant message:

public showmessagedialog(message) {     let config = new mddialogconfig()       .title('message:')       .textcontent(message)       .ok('got it');      this.dialog.open(mddialogbasic, this.element, config);   } 

now, want know , how should call message present messagetodisplay when observable ready.

i t better if can tell me how can show loader while observable waiting receive string , when there present it...

i tried this:

public sendupdate() {      this._mtservice.sendcurrentupdate(this.mylist).subscribe(      res => this.messagetodisplay = res,      error => this.messagetodisplay = error      );     this.showmessagedialog(this.messagetodisplay);      } 

but happens here first time click on update see empty pop-up , if click on again see pop-up message, obvious happens because string didnt came yet, how on it?

thanks!

the functions pass subscribe() called later/asynchronously, hence need call showmessagedialog() later well:

public sendupdate() {    this.showloader();    this._mtservice.sendcurrentupdate(this.mylist).subscribe(      res   => { this.stoploader(); this.showmessagedialog(res); },      error => { this.stoploader(); this.showmessagedialog(error); }    );  } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -