mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-04-04 04:32:40 +00:00
35 lines
1010 B
TypeScript
35 lines
1010 B
TypeScript
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
|
import { MarkdownService } from '../services/markdown.service';
|
|
import { WebSocketService } from '../services/websocket.service';
|
|
|
|
import { Message } from './message';
|
|
|
|
@Component({
|
|
selector: 'app-messages',
|
|
templateUrl: './messages.component.html',
|
|
styleUrls: ['./messages.component.scss']
|
|
})
|
|
export class MessagesComponent implements OnInit {
|
|
messages: Message[] = [];
|
|
constructor(
|
|
private markdownService: MarkdownService,
|
|
private websocketService: WebSocketService,
|
|
private changeDetectorRef: ChangeDetectorRef
|
|
) {}
|
|
|
|
convert(text: string) {
|
|
return this.markdownService.convertToHtml(text);
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.websocketService.connect();
|
|
this.websocketService.observeKey<Message>('message').subscribe(
|
|
(event) => {
|
|
this.messages.push(event.data);
|
|
event.data.message = this.convert(event.data.message);
|
|
this.changeDetectorRef.detectChanges();
|
|
}
|
|
);
|
|
}
|
|
}
|