Angular is throwing the following error:
"Type 'Object' is missing the following properties from type 'never[]': length, pop, push, concat, and 28 more.
this.movies = data;"
// movie-list.component.ts
// ...
export class MovieListComponent implements OnInit {
movies = [];
constructor(
private apiService: ApiService) { }
ngOnInit() {
this.apiService.getMovies().subscribe(
data => {
this.movies = data;
})}
}
I´ve changed the "movie" variable for
movies: any[] = [];
but the error still appears
// api.service.ts
// ...
export class ApiService {
baseUrl = 'http://127.0.0.1:8000/api/movies/'
headers = new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'token 61a1e3bfcfaea4fceee08d52fa132c788204d5e4'
})
constructor(
private http: HttpClient
) {}
getMovies() {
return this.http.get(this.baseUrl, {headers: this.headers});
}
}
console.log(data)
(3) [{…}, {…}, {…}]
0: {id: 1, title: 'Titanic', description: 'Romantic movie '}
1: {id: 2, title: 'Avatar', description: 'SiFy movie'}
2: {id: 4, title: 'Dune', description: 'SiFy movie'}
length: 3
[[Prototype]]: Array(0)