mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-07-01 07:06:22 +00:00
Rename LogsComponent to MessagesComponent
This commit is contained in:
32
src/app/messages/messages.component.ts
Normal file
32
src/app/messages/messages.component.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { MarkdownService } from '../markdown.service';
|
||||
import { WebSocketService } from '../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
|
||||
) {}
|
||||
|
||||
convert(text: string) {
|
||||
return this.markdownService.convertToHtml(text);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.websocketService.observeAnchor<Message>('message').subscribe(
|
||||
(event) => {
|
||||
this.messages.push(event.data);
|
||||
event.data.message = this.convert(event.data.message);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user