在我的ng2服務中,我有一個有2個http.get調用的方法。 功能看起來是這樣的:在Angular 2中使用兩個http.get調用的Observable類型
getInfo(userId: number): any {
this.http
.get(apiUrl, options)
.map(response => response.json())
.subscribe(example => {
this.example.FirstName = example.FirstName;
this.example.LastName = example.LastName;
this.http
.get(`/api/${userId}`)
.map(response => response.json())
.subscribe(example => {
this.example.Street = example.Street;
this.example.City = example.City;
return this.example;
});
});
}
唯一的問題是,在我的部分,我可以不同意這個功能,因爲它是Observable<Example>
類型的不行。
如果我Observable<Example>
取代類型的任何的功能我得到:
聲明類型既不是「無效」,也沒有「任意」必須返回值
但我也有一個返回功能一個值,在響應之後。
如何在沒有兩個獨立功能的情況下做到這一點?
是的,我沒有檢查這個答案:https://stackoverflow.com/a/36712707/3264998
值得一看[這個答案](http://stackoverflow.com/a/37748799/2435473) –