Issue
so iam tying to show api using ionic but this error show
Type 'any[]' is not assignable to type 'never[]'. Type 'any' is not assignable to type 'never'.
import { Component, OnInit } from '@angular/core';
import { LoadingController } from '@ionic/angular';
import { MovieService } from 'src/app/services/movie.service';
@Component({
selector: 'app-movies',
templateUrl: './movies.page.html',
styleUrls: ['./movies.page.scss'],
})
export class MoviesPage implements OnInit {
movies = [];
currentPage = 1;
constructor(private movieService: MovieService, private loadingCtrl: LoadingController) { }
ngOnInit() {
this.loadMovies();
}
async loadMovies() {
const loading = await this.loadingCtrl.create({
message: 'Loading..',
spinner: 'circles',
});
await loading.present();
this.movieService.getTopRatedMovies(this.currentPage).subscribe((res) => {
loading.dismiss();
this.movies = [...this.movies, ...res.results];
console.log(res);
});
}
}
Solution
TS doesn't infer a type from the empty array.
You'll need to defined that type : movies: Movie[] = []
;
Answered By - Matthieu Riegler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.