import { Injectable } from '@angular/core' ; import { Observable , of } from 'rxjs' ; import { Message } from '../../models/message' ; @ Injectable ( { providedIn : 'root' , } ) export class ChatService { messages : Array < Message > = [ { id : 0 , text : 'Hello there' , } , { id : 1 , text : 'Hi' , } , { id : 2 , text : "How're you doing?" , } , { id : 3 , text : 'Perfectly fine. How are you ?' , } , ] ; constructor ( ) { } author return { Observable } getMessages ( ) { return of ( this . processMessages ( this . messages ) ) ; } author param message { Array < Message > } return { Array < Message > } processMessages ( messages ) { return messages . map ( ( message ) => { const id = Math . ceil ( Math . random ( ) * 3 + 1 ) ; message . userId = id ; message . userImage = `assets/images/users/${ id }.jpg` ; return message ; } ) ; } }