mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 02: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 { MarkdownService } from '../markdown.service';
|
||||||
import { WebSocketService } from '../websocket.service';
|
import { WebSocketService } from '../websocket.service';
|
||||||
|
|
||||||
@ -13,7 +13,8 @@ export class MessagesComponent implements OnInit {
|
|||||||
messages: Message[] = [];
|
messages: Message[] = [];
|
||||||
constructor(
|
constructor(
|
||||||
private markdownService: MarkdownService,
|
private markdownService: MarkdownService,
|
||||||
private websocketService: WebSocketService
|
private websocketService: WebSocketService,
|
||||||
|
private changeDetectorRef: ChangeDetectorRef
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
convert(text: string) {
|
convert(text: string) {
|
||||||
@ -24,11 +25,10 @@ export class MessagesComponent implements OnInit {
|
|||||||
this.websocketService.connect();
|
this.websocketService.connect();
|
||||||
this.websocketService.observeAnchor<Message>('message').subscribe(
|
this.websocketService.observeAnchor<Message>('message').subscribe(
|
||||||
(event) => {
|
(event) => {
|
||||||
console.log(event.data);
|
|
||||||
this.messages.push(event.data);
|
this.messages.push(event.data);
|
||||||
event.data.message = this.convert(event.data.message);
|
event.data.message = this.convert(event.data.message);
|
||||||
|
this.changeDetectorRef.detectChanges();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user