0

I'm building an app in angular and C#.

I'm sending a message (using SignalR) from one user to another. The message is sent as an Alert (popup window) to the other user, but the problem is that I want to redirect that user (the one who got the message) to another component after clicking the 'OK' button on the alert window. I don't understand how to bind the button on the alert window to the event in Angular?

Here is my service, where I'm adding the alert message:

    public addListenerInvitation(){
    this.hubConnection.on("InvitePlayer", (message: string, sendToUser: 
      string) => {
          this.inviteMsg=message;
          console.log("invitation message: ", this.inviteMsg);
          alert(this.inviteMsg);
      })
    }
Inbar Manor
  • 101
  • 1
  • 10
  • Based on Matthieu Riegler answer, maybe this can help you: https://stackoverflow.com/questions/9394131/go-to-url-after-ok-button-if-alert-is-pressed – Ricardo Machado Feb 25 '23 at 19:10

1 Answers1

1

alert is a native function of the browser. It will "block" the thread until the user clicked on okay, so you can consider it as synchronous.

Any code after the alert() will run when the user click OK.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • When I'm adding this line code: `this.router.navigateByUrl("/game");` after `alert` I immediately redirect to another component without showing that alert popup window. Does it make sense? – Inbar Manor Feb 26 '23 at 11:11