// interface
export interface IMovie {
id: number;
name: string;
releaseDate: string;
genre: string;
}
//component:
movie: IMovie = null;
ngOnInit() {
this.route.paramMap.subscribe((params: ParamMap) => {
const movie_id = parseInt(params.get('movie_id'), 10);
this.movieService.getMovieById(movie_id)
.subscribe((movie) => this.movie = movie);
});
}
//service
getMovieById(movie_id: number): Observable<IMovie> {
return this.http.get<IMovie>(url);
}
当我尝试以组件代码进行打印时,我能够看到对象(console.log(movie)
),但我不明白为什么未发生映射,即对象-> IMovie
。 / p>
我以不同的方式尝试了无用的东西。