import { Component , OnDestroy , OnInit } from '@angular/core' ; import { ChatService } from 'src/app/core/services/chat.service' ; import { Message } from '../../models/message' ; @ Component ( { selector : 'app-chat' , templateUrl : './chat.component.html' , styleUrls : [ './chat.component.scss' ] , } ) export class ChatComponent implements OnInit { chatMessages : Array < Message > = [ ] ; constructor ( private chatService ) { } ngOnInit ( ) { this . chatService . getMessages ( ) . subscribe ( ( messages ) => { this . chatMessages = messages ; } ) ; } author param message { Message } newMessageSent ( message ) { this . chatMessages = [ ... this . chatMessages , message ] ; } }