so, i have a chat messenger app. i started with a simple array or strings to hold the chat messages in typescript chat.ts . This component has the template chat.html which shows the messages as:
chat.html
<div class="chat-container">
<div *ngFor="let item of items">
<p>item</p>
</div>
</div>
chat.ts
@IonicPage()
@Component({
selector: 'page-chat',
templateUrl: 'chat.html'
})
export class ChatPage {
items:string[] = []
send(msg:string){ this.items.push(msg);}
}
This works fine as expected. However, the items array is pretty much confined within the Chat component. I wanted it to be accessible from other pages etc. So i decided to move it out of it and create a dedicated class to hold it as follows: message-queue.ts
export class MessageQueue{
static items: Message[] = [];
constructor(){ }
}
i replace all the this.items in the chat.ts to MessageQueue.items and this all seems fine. However, now I am stuck as how do i refer to this variable in the chat.html ?
replacing:
<div *ngFor="let item of items">
to
<div *ngFor="let item of MessageQueue.items">
wont work