I am writing an Angular2 application. I want to display messages using an interface and an array containing all the messages. Here is the interesting part of my TypeScript component:
export class ChatComponent
{
messages: message[];
constructor()
{
this.messages.push({from: 'me', time: new Date().getTime(), type: 'text', value: 'Hallo Welt!', sent: new Date().getTime(), delivered: 0, read: 0});
}
}
interface message
{
from: string;
time: number;
type: string;
value: string;
sent: number;
delivered: number;
read: number;
}
As you can see from TypeScript side of things everything looks alright (I guess). Displaying stuff in the template worked fine, in this case I am using the following:
<div class = "message" *ngFor = "let message of messages">
<div>{{message.value}}</div>
<div>{{message.time}}</div>
</div>
When just using an array and filling it with objects this setup is working fine. But as soon as I use the interface message and the array I get
EXCEPTION: Error in :0:0 caused by: this.messages is undefined
I feel like it's some stupid mistake or misunderstanding, but couldn't find anything useful. Why should this.messages be undefined?