【问题标题】:i cant fix the .map on http post clienti cant fix the .map on http post client
【发布时间】:2022-12-01 20:58:26
【问题描述】:
public postForObjecty(endpoint: any, data: any) {
        return new Promise((resolve, reject) => {
            let url = this.createBasicUrl(endpoint);
            let _data = this.arrangeData(data);
            let headers: any = new Headers()
            let token = `Bearer ${RestProvider.BEARER_TOKEN}`;
            headers.append('Authorization', token);
            this.http.post(url, _data, { headers: headers })
                .map((res: { json: () => any; }) => res.json())
                .subscribe((data: unknown) => {
                    resolve(data);
                }, (err: any) => {
                    reject(err);
                });
        });
    }

i want to post and get methond to backend but i cant fix this code

.map

this doesnt work,

if i could fix this .map method it will be done

【问题讨论】:

    标签: json angular http get


    【解决方案1】:

    You want to use RxJS map method. For that you need to .pipe the observable stream like so:

      public postForObjecty(endpoint: any, data: any) {
        return new Promise((resolve, reject) => {
          let url = this.createBasicUrl(endpoint);
          let _data = this.arrangeData(data);
          let headers: any = new Headers()
          let token = `Bearer ${RestProvider.BEARER_TOKEN}`;
          headers.append('Authorization', token);
          this.http.post(url, _data, { headers: headers })
            .pipe(map((res: { json: () => any; }) => res.json()))
            .subscribe((data: unknown) => {
              resolve(data);
            }, (err: any) => {
              reject(err);
            });
        });
      }
    

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 2015-04-25
      • 2022-12-19
      • 2021-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 2017-12-15
      相关资源
      最近更新 更多