如何在Angular中请求api删除操作

如何在Angular中请求api删除操作,angular,rest,api,http,http-method,Angular,Rest,Api,Http,Http Method,所以在我的angular项目中,我在workspace.service.ts文件中调用了API,并且我能够创建其他请求,如getWorkspace和CreateSpace等。。但不能删除请求 我不熟悉API调用或请求后端的东西,但我认为我需要做一些删除操作的调用 所以我在我的项目中尝试做的是创建一个删除按钮,允许用户删除当前工作区 export class Workspace { guid: string; name: string; description: strin

所以在我的angular项目中,我在workspace.service.ts文件中调用了API,并且我能够创建其他请求,如getWorkspace和CreateSpace等。。但不能删除请求

我不熟悉API调用或请求后端的东西,但我认为我需要做一些删除操作的调用

所以我在我的项目中尝试做的是创建一个删除按钮,允许用户删除当前工作区

export class Workspace {
    guid: string;
    name: string;
    description: string;
    type: WorkspaceType;
    userRole: WorkspaceRole;
    charts?: any[];
}
 deleteWorkspace(workspace: Workspace) {
    return this.http.delete<Workspace>(`${environment.api.chart}/${workspace.guid}`);
  }
从'@angular/core'导入{Injectable};
从'@angular/common/http'导入{HttpClient};
从'src/environments/environment'导入{environment};
从“rxjs/operators”导入{first,tap};
从'src/app/shared/models/Workspace.model'导入{Workspace}//上面的代码
导出类工作空间服务{
加载的工作空间:工作空间[]
构造函数(私有http:HttpClient){}
getWorkspace(guid:字符串){
返回此.http.get(`${environment.api.chart}/workspaces/${guid}`).pipe(first());
}
getUserWorkspace(){
返回此.http.get(`${environment.api.chart}/workspaces`).pipe(点击(workspaces=>this.loadedWorkspaces=workspaces),first());
}
createWorkspace(工作空间:工作空间){
返回这个.http.post(`${environment.api.chart}/workspace`,workspace.pipe(first());
}
deleteWorkspace(工作空间:工作空间){
//删除请求
}

我真的不确定如何处理deleteWorkspace,我尝试从上面复制代码,只是将HTTP方法更改为this.HTTP.delete,但“workspace”上出现错误,它说,“没有重载匹配此调用”。

您只需传递workspace id即可删除工作区

export class Workspace {
    guid: string;
    name: string;
    description: string;
    type: WorkspaceType;
    userRole: WorkspaceRole;
    charts?: any[];
}
 deleteWorkspace(workspace: Workspace) {
    return this.http.delete<Workspace>(`${environment.api.chart}/${workspace.guid}`);
  }
deleteSpace(工作区:工作区){
返回此.http.delete(`${environment.api.chart}/${workspace.guid}`);
}


如果要在删除请求中传递正文,此问题可能会帮助您:

您只需传递工作区id即可删除工作区

export class Workspace {
    guid: string;
    name: string;
    description: string;
    type: WorkspaceType;
    userRole: WorkspaceRole;
    charts?: any[];
}
 deleteWorkspace(workspace: Workspace) {
    return this.http.delete<Workspace>(`${environment.api.chart}/${workspace.guid}`);
  }
deleteSpace(工作区:工作区){
返回此.http.delete(`${environment.api.chart}/${workspace.guid}`);
}

如果要在删除请求中传递正文,此问题可能会帮助您: