我的模拟服务中具有以下数据结构,并且由于映射的结果,在完成以下链后,我收到NaN,但是服务中的值为数字。
我在做什么错了?
{
"person": [{
"val1": 1,
"val2": 2
}],
"facility": [{
"val3": 3,
"val4": 4
}],
"exposure": [{
"val5": 5
}]
}
我试图获取响应结果的组件:
import { Injectable } from '@angular/core';
import { Person } from './entities/person';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class DataService {
apiUrl1: string = 'http://localhost:3000/person/?';
apiUrl2: string = 'http://localhost:3000/facility/?';
apiUrl3: string = 'http://localhost:3000/exposure/?';
constructor(private http: HttpClient) {
}
createPerson(person: Person): Observable<any> {
return (this.http.post(this.apiUrl1, person)
.flatMap((response: any) => this.http.get(this.apiUrl2 + response.val1)))
}
getData(arg): Observable<any> {
return (this.http.get(this.apiUrl1 + arg)
.flatMap((response: any) => this.http.get(this.apiUrl2 + response.val1))
.flatMap((response: any) => this.http.get(this.apiUrl3 + response.val2))
.map((response: any) => response.val3 * response.val5)
)
}
}