首页 > 解决方案 > Angular 服务删除方法

问题描述

我正在尝试使用角度服务delete方法删除客户,但我不知道如何id从角度组件动态传递参数。谁能告诉我如何id动态传递?

deleteCustomerById(id: number): Observable<number>
      {
        const httpOptions =
        {
          headers: new HttpHeaders({ 'Content-Type': 'application/json'})
        };
          return this.http.delete<number>('http://localhost:58274/api/Customers/{id}' + id, httpOptions);
      }

标签: angularangular-serviceshttp-delete

解决方案


您正在寻找:

 this.http.delete<number>(`http://localhost:58274/api/Customers/${id}`, httpOptions);

细节


推荐阅读