从Angular 4迁移到Angular6。http似乎有所改变。在下面,我用于在请求选项中设置搜索。现在看来已不再如此。有人可以告诉我现在应该是什么样吗?
getSummaryStatistics(mid: string, cp: string): Observable<SummaryStatistics> {
const params: HttpParams = new HttpParams();
params.set('mid', mid);
params.set('cp', cp);
const headers = new HttpHeaders({
'Accept': 'application/json'
});
let options = new Request({
headers: headers,
search: params //THIS IS WRONG
});
return this.http.get('Summary/SummaryStatistics', options)
.map(response => <SummaryStatistics>response.json()); //ALSO .map NO LONG SEEMS TO WORK
}
新尝试
答案 0 :(得分:1)
这是Angular 6中的示例:
getCadastralInformationByCoords(lat: any, lng: any, geom: boolean = true): Observable<CadastralParcel> {
let urlToCall = urlAPIParcel;
urlToCall += '?corx=' + lat;
urlToCall += '&cory=' + lng;
urlToCall += '&geom=' + geom;
return this._http.get<CadastralParcel>(urlToCall).pipe(
catchError(err => {
return throwError(err);
}));
}
自Angular 5起,您无需使用response.json()
,因为该方法默认情况下会键入调用。有关更多信息,请参见Oficcial docs