angular - 如何将 HTTP 响应映射到用户定义的类型?
问题描述
// 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);
}
当我尝试在组件代码中打印时,我能够看到 Object ( console.log(movie)
),但我不明白为什么IMovie
没有发生映射,即 Object ->。
我尝试了不同的方式,但对我没有任何效果。
解决方案
推荐阅读
- cognos-11 - 我在哪里可以设置 cognos analytics 11 报告缓存打开/关闭
- python - 点积两个 4D Numpy 数组
- css - 如何将卡片内的所有内容对齐?
- php - Wordpress 数字分页未出现在自定义循环中
- node.js - “sudo npm install -g npm”减慢开发服务器的启动速度
- python - 如何根据列表中元组的第二个元素的总和对列表进行排序?
- azure - 如何使用 Terraform 在 Azure 中创建多租户服务主体
- javascript - 从本地前端应用程序到本地后端 Sails JS Blueprint REST 路由的 XHR 请求出现 401 错误
- algorithm - 执行不同时期的功能
- react-native - 禁用特定屏幕的抽屉