Fix messages not showing (detectChanges())

This commit is contained in:
Kristóf Tóth 2018-02-16 17:49:57 +01:00
parent 1da9489be8
commit 4a0424ef34

View File

@ -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();
}
);
}
}