export class AppComponent implements OnInit {
movieList: Observable<any>;
constructor(private AppService:AppService){
}
ngOnInit() {
this.getMovies();
}
getMovies() {
this.movieList = this.AppService.getMovies().map(movie => {
return {
name: movie.name
}
});
this.movieList.subscribe(data => {
debugger;
})
}
}
我想对observable this.movieList执行Rxjs操作,但是当我订阅this.movieList时,调试器中的Data返回undefined
答案 0 :(得分:0)
问题是你的getMovies返回一个集合,在地图中你将它视为单个项目。如果你想到这一点,它应该wotk
this.movieList = this.AppService.getMovies().map(movies => movies.map(movie => { return { name: movie.name } }));