Hey guys I am using the OMDB API to get the list of movies. I get the data in the console but I cant loop through it to show it in the UI. It just returns an empty.
export class example {
movies: Movie[];
search: string;
constructor(private service: MovieService) {}
getMovies(): void {
this.service.get(this.search).then((result) => {
this.movies = [result];
console.log(result)
});
}
}
When I console log the data I am getting this:
in my HTML component I loop through it like this:
<div *ngFor="let movie of movies">
<div>{{movie.Title}}<span>{{movie.Rated}}</span></div>
</div>
But this is not working. It just doesnt do anything.
Can someone help me please? I would really appreciate it.
Thanks
this.movies = [result];tothis.movies = result.Search;and lets see what will happeningresultobject has a property calledSearchthat is an array with the data you are looking for. You need to pass this value to yourmovieslist.service.get(...)is not returning aMovieobject. It's returning an object like:{Search: Movie[]; totalResults: number; Response: boolean}. You need to change this signature. Just to make a quickly check try to use this:this.movies = (<any>result).Search;