I am following this tutorial https://blog.briebug.com/blog/making-use-of-websockets-in-angular and it all works. However, the result is always [object Object]
and I cannot figure out how to get the string value of what I sent displayed.
This is how the content is displayed:
<ul>
<li *ngFor="let message of messages">{{ message }}</li>
</u>
and this is how the socket is used:
messages: Message[] = [];
destroyed$ = new Subject();
constructor(private webSocket: WebSocketService) {}
ngOnInit() {
this.webSocket.connect().pipe(
takeUntil(this.destroyed$)
).subscribe(messages => this.messages.push(messages));
}
sendMessage() {
this.webSocket.send({ message: this.msgCtrl.value });
this.msgCtrl.setValue('');
}
The tutorial uses the socket: wss://echo.websocket.org. So all it is doing is sending an 'echo' back of what I sent it. How can I display what it is sending back?