【发布时间】:2017-03-26 21:03:07
【问题描述】:
我的想法是这样做:
getCast(id:number, numCast:number){
return this.getCredits(id)
.map( credits => credits.cast.length >= numCast ? credits.cast.slice(0,numCast) : credits.cast )
.subscribe(character => {
for(let index in character){
return this.getPerson(character[index].id);
}
});
}
getPerson(person_id:number) {
return this.http.get('https://api.themoviedb.org/3/person/'+person_id+'?'+this.apiKey)
.map(data => JSON.parse(data['_body']))
}
this.mvs.getCast(this.route.snapshot.params['id'], 6)
.subscribe( data => { console.log(data); })
但它根本不起作用。 控制台中的错误说:
_this.mvs.getCast(...).subscribe is not a function
【问题讨论】:
-
我不确定您要在这里做什么。如果您在映射后已经订阅了
this.mvs.getCast,为什么还要在this.mvs.getCast订阅?请你提供一个 Plunker 吗? -
Beucase getCast 应该返回一个可观察的演员,为此我需要获取电影的演员阵容,然后我需要每个演员的详细信息。我想从 this.getPerson(character[index].id); 返回 observable
-
如果你想在
getCast之外subscribe,你不应该在subscribe里面。改用另一个map,所以你仍然返回一个可观察的..
标签: angular typescript rxjs observable