Issue
I have a script that connects to server using WebSocket
export class AppComponent {
connection_status = false;
message = '';
public connect() {
this.socket = io('http://localhost:5001');
this.socket.on('connected', this.connection_established);
}
}
I would like to change the connection_status
variable when connected
message is received and save the content of the message to message
variable.
Solution
export class AppComponent {
connection_status = false;
message = '';
public connect() {
this.socket = io('http://localhost:5001');
this.socket.on('connected', this.connection_established.bind(this));
}
connection_established() {
this.connection_established = true;
this.message = 'connected';
}
}
Answered By - Ignasi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.