mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-15 23:51:57 +00:00
Fix messages not showing (detectChanges())
This commit is contained in:
parent
1da9489be8
commit
4a0424ef34
@ -1,4 +1,4 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
||||
import { MarkdownService } from '../markdown.service';
|
||||
import { WebSocketService } from '../websocket.service';
|
||||
|
||||
@ -13,7 +13,8 @@ export class MessagesComponent implements OnInit {
|
||||
messages: Message[] = [];
|
||||
constructor(
|
||||
private markdownService: MarkdownService,
|
||||
private websocketService: WebSocketService
|
||||
private websocketService: WebSocketService,
|
||||
private changeDetectorRef: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
convert(text: string) {
|
||||
@ -24,11 +25,10 @@ export class MessagesComponent implements OnInit {
|
||||
this.websocketService.connect();
|
||||
this.websocketService.observeAnchor<Message>('message').subscribe(
|
||||
(event) => {
|
||||
console.log(event.data);
|
||||
this.messages.push(event.data);
|
||||
event.data.message = this.convert(event.data.message);
|
||||
this.changeDetectorRef.detectChanges();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user