属性' concatmap'在类型上不存在

发布于 2025-01-30 08:22:12 字数 719 浏览 2 评论 0原文

请帮忙,我试图从Angular发送一个请求...当我尝试使用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';

Please help, i am trying to send a put request from Angular...when i try to use concatMap i get the error

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);
        });
      }

I get the below error..please anyone knows what i am doing wrong

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

I have tried the following, nothing worked, still same error

import 'rxjs/add/operator/concatMap';

import { concatMap } from 'rxjs/operators';

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城花音 2025-02-06 08:22:12

我能够通过将管道添加到我的代码中来解决此问题

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);
    })
);

}

I was able to solve this by adding pipe to my code

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);
    })
);

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文