这里我的方法工作正常,能够订阅结果。
fetchIncidentDetails(incidentId: number): Observable<any> {
const url = `${AppUtils.INCIDENT_SEARCH}/${incidentId}/${+localStorage.getItem(AppUtils.PERSON_CODE)}`;
let incident: Observable<IncidentReportModel>;
incident= this.http.get(url)
.map(response => response.json().result)
.catch(this.handleError);
return incident;
}
public setIncidents(incidents: IncidentReportModel) {
this.incidents = incidents;
}
如果我在地图中添加一个语句,则无法订阅响应。 我需要设置响应值。我怎样才能做到这一点。
.map(response =>{response.json().result; this.setIncidents(response.json().result)})})
答案 0 :(得分:0)
我如何理解你想做这样的事情
fetchIncidentDetails(incidentId: number): Observable<any> {
const url = `${AppUtils.INCIDENT_SEARCH}/${incidentId}/${+localStorage.getItem(AppUtils.PERSON_CODE)}`;
let incident: Observable<IncidentReportModel>;
incident= this.http.get(url)
.map(response => {
this.setIncidents(response.json().result)
return response.json().result
})
.catch(this.handleError);
return incident;
}
了解java scrippt
中的工作arrow function(param1, param2, …, paramN) => expression
// equivalent to: (param1, param2, …, paramN) => { return expression; }