我从Angular 5模板开始,并将其转换为Ang 6。 https://github.com/mmacneil/AngularASPNETCore2WebApiAuth
我知道RxJS已更改,例如RxJS v5.x至v6。 因此,如果.map已完全更改,那么如何将此代码转换为v6。
register(email: string, password: string, firstName: string, lastName: string,location: string, gender:string, birthDate:any): Observable<UserRegistration> {
let body = JSON.stringify({ email, password, firstName, lastName,location,gender,birthDate });
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.baseUrl + "/accounts", body, options)
.map(res => true)
.catch(this.handleError);
}
UserRegistration
export interface UserRegistration {
email: string;
password: string;
firstName: string;
lastName: string;
location: string;
birthDate: any;
gender: string;
}
答案 0 :(得分:1)
return this.http.post(this.baseUrl + "/accounts", body, options).pipe(
map(res => true),
catchError(this.handleError)
}
知道,如果您不想将所有RxJs代码从5转换为6,现在可以安装rxjs-compat
,它将同时支持两个版本(假设您也安装了6)
使用ng update
将ng5升级到ng6时,将自动安装rxjs-compat
。有关更多信息,请参见https://blog.angular.io/version-6-of-angular-now-available-cc56b0efa7a4#7a6c。
答案 1 :(得分:1)
使用管道运算符。将catch
替换为catchError
return this.http.post(this.baseUrl + "/accounts", body, options)
.pipe(
map(res => true),
catchError(this.handleError)
)
}