属性'concatMap'在类型"可观察"上不存在



请帮忙,我正试图从Angular发送一个put请求…当我尝试使用concatMap时,我得到错误

public updateUser(token: string, requestBody: any): Observable<User> {
const myHeaders = new HttpHeaders({ 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token });
return this.http.put<User>(this.baseUrl + "api/user", requestBody, { headers: myHeaders }).concatMap(data => {
return of(data);
});
}

我得到下面的错误,请任何人知道我做错了什么

Property 'concatMap' does not exist on type 'Observable<User>'.

我已经尝试了以下,没有工作,仍然是相同的错误

import 'rxjs/add/operator/concatMap';
import { concatMap } from 'rxjs/operators';

我可以通过在我的代码中添加管道来解决这个问题

public updateUser(token: string, requestBody: any): Observable<User> {
const myHeaders = new HttpHeaders({ 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token });
return this.http.put<User>(this.baseUrl + "api/user", requestBody, { headers: myHeaders })
.pipe( 
concatMap(data => {
return of(data);
})
);

}

最新更新