I'm currently working on creating a movie catalog using Angular and Ionic. Within the Movie class, I have properties for id, title, image, and plot.
On the initial page of the app, only the id, title, and image are displayed, while the plot is omitted.
Movie Class
export class Movie{
id: number;
title: string;
img: string;
plot?: string;
}
Within the main typescript file, I am populating the movie details in the following manner:
export class MainPage implements OnInit{
movies: Movie[];
getMovies(){
this.movies = [{id: 1, title: 'test', img: 'img1'}]
}
ngOnInit(){
this.getMovies();
}
}
However, this results in the following error:
Error TS1112: A class member cannot be declared optional. The issue lies with the 'plot' variable.
Is there a way to achieve my intended goal? Are there any alternative solutions?
Thank you in advance for your assistance!