There were 2 model.ts files utilized in this scenario.
The first one is profile.model.ts
export interface Profile {
username: string;
nickname: string;
image: string;
}
'The second one, comment.model.ts' makes use of 'profile.model.ts'.
In comment.model.ts
import { Profile } from '.';
export interface Comment {
author: Profile;
content: string;
creatat?: Date;
}
Now for the comment.component.ts file
...
export class CommentComponent implements DoCheck {
...
content: string; // Retrieve value from ngModel in comment.component.html
comments: Comment; // Pertains to comment.model.ts
}
...
addComment() {
this.comments.author.nickname = 'Test Nickname';
this.comments = {
content: this.content
};
...
}
Upon running the addComment(), an error occurred as follows:
ERROR TypeError: Cannot read property 'author' of undefined
What could be causing this issue?
Appreciate your guidance and suggestions in advance.