0
我的想法是這樣:如何從訂閱中返回觀察值以訂閱?
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'中再次訂閱?你能提供一個Plunker嗎? – brians69
Beucase getCast應該返回演員的可觀察者,爲此我需要獲得電影的演員陣容,然後我需要每個演員的細節。 我想從** this.getPerson(character [index] .id)返回觀察值; ** – Donovant
如果你想在'getCast'之外'訂閱',你不應該在'subscribe'裏面。使用另一個'map'來代替,所以你仍然返回一個可觀察的值。 – jonrsharpe