首页 文章

转换为对Angular 7 [暂停]的发布请求

提问于
浏览
-2
return super.post(this.getFullUrl(url), body, this.requestOptions())
        .catch(this.onCatch.bind(this))
        .do((res: Response) => {
            this.onSubscribeSuccess(res);
        }, (error: any) => {
            this.onSubscribeError(error);
        })
        .finally(() => {
            this.onFinally();
        });

我想将此代码转换为Angular版本7.1.0

3 回答

  • 0

    试试这种方式

    try{
       this.http.post(URL, param, options)
        .subscribe(data => {
           console.log(data);  
           this.onSubscribeSuccess(res);  
       });              
    }
    catch(error){
      console.log(error);    
    }
    
  • 0

    这是我的一个帖子请求参考,如果这有帮助:

    createProduct(product: Product): Observable<Product> {
        const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
        return this.http.post<Product>(this.productsUrl, product, { headers: headers })
          .pipe(
            tap(data => console.log('createProduct: ' + JSON.stringify(data))),
            catchError(this.handleError)
          );
      }
    
  • 0

    更好的方法:

    this.http.post(URL, param, options)
        .subscribe(data => {
           console.log(data);  
           this.onSubscribeSuccess(res);  
       }, (err) => {
               console.log(err);
           }
      );
    

相关问题