我们正尝试从Angular 4升级到Angular9。我已成功升级了Package.json中定义的所有软件包。
我目前遇到的问题是@ angular / http中的RequestOptions已被弃用,我在尝试在Angular 9中找到等效项时遇到了麻烦。
原始代码:
import { Http, Response, Headers, RequestOptions } from '@angular/http';
private getDefaultRequestOptionsObservable(headers: Headers = null): Observable<RequestOptions> {
return this.userService.getUser()
.flatMap(user => {
if (headers == null) {
headers = new Headers();
}
let userSessionHeader = headers.get(this.userSessionHeaderName);
if (userSessionHeader == null || userSessionHeader === '') {
headers.append(this.userSessionHeaderName, user.userSession);
}
return Observable.of(new RequestOptions({ withCredentials: true, headers: headers }));
});
}
我已将进口商品替换为:
import { HttpClient, HttpHeaders, HttpParams, HttpRequest } from '@angular/common/http';
并且我还从rxjs导入了'of',准备删除显式返回Observable.of(.....)以返回of(...)
如果有人可以帮助我重写上面的内容,那就太好了。我已将方法签名替换为:
private getDefaultRequestOptionsObservable(headers: Headers = null): Observable<HttpRequest<any>> {
对return of(new HttpRequest......
的任何帮助将不胜感激。