I am new to Angular2 and encountering a problem. I have developed a component called info. In the info.component.ts file, I am initializing objects in the following way:
import { Comm } from '../shared/comments';
...
const VASACOM: Comm = {
name: 'Vasa',
id: 122,
comments: [
{
rating: 5,
comment: "Some commment",
date: "2012-10-16T17:57:28.556094Z"
},
{
rating: 4,
comment: "Other comment",
date: "2014-09-05T17:57:28.556094Z"
}
]
};
The class Comm in comments.ts:
export class Comm {
name: string;
id: number;
comments: Comment[];
constructor(name:string,id:number,comments:Comment[]){
this.name = name;
this.id = id;
this.comments = comments;
}
}
export class Comment {
rating: number;
comment: string;
date: string;
}
However, I encounter an error:
error TS2322: Object literal may only specify know properties, and 'comments' does not exist in type 'Comm'
Can you point out what mistake I made?
p.s. I am aware that we can create 2 separate objects, one using the Comm class and the other with Comment, but I prefer keeping them in a single object.