为了账号安全,请及时绑定邮箱和手机立即绑定

角度删除 - API 未收到调用

角度删除 - API 未收到调用

蓝山帝景 2022-01-01 20:32:47
我有以下自动生成的代码 (NSwag Studio) - 唯一的修改是withCredentials我为 Windows Auth(内网应用程序)添加的代码。    deleteObjective(id: number): Observable<ObjectiveDTO> {        let url_ = this.baseUrl + "/api/Objectives/{id}";        if (id === undefined || id === null)            throw new Error("The parameter 'id' must be defined.");        url_ = url_.replace("{id}", encodeURIComponent("" + id));         url_ = url_.replace(/[?&]$/, "");        let options_ : any = {            observe: "response",            responseType: "blob",            withCredentials: true,            headers: new HttpHeaders({                "Accept": "application/json"            })        };        return this.http.request("delete", url_, options_).pipe(_observableMergeMap((response_ : any) => {            return this.processDeleteObjective(response_);        })).pipe(_observableCatch((response_: any) => {            if (response_ instanceof HttpResponseBase) {                try {                    return this.processDeleteObjective(<any>response_);                } catch (e) {                    return <Observable<ObjectiveDTO>><any>_observableThrow(e);                }            } else                return <Observable<ObjectiveDTO>><any>_observableThrow(response_);        }));    }生成的服务中的其他一切工作正常(这是唯一的删除),但这实际上没有发送任何流量 - 在 Chrome 网络拉出(F12)中,没有对 API 的调用,API 也没有收到任何内容。我从我的组件中调用它,如下所示:  deleteObjective(): void {    if (confirm('Are you sure you want to delete this objective? This cannot be un-done.')) {      if (this.objective.id !== 0)        this.service.deleteObjective(this.objective.id);      for (var i = 0; i < this.objectives.length; i++) {        if (this.objectives[i] === this.objective) {          this.objectives.splice(i, 1);        }      }    }  }并且拼接肯定是有效的。如果我放在debuggerhttp 请求之前,它会调用它。控制台中没有错误。有任何想法吗?我是 angular 的新手,但对编程很老。
查看完整描述

2 回答

?
梵蒂冈之花

TA贡献1900条经验 获得超5个赞

当您从服务调用该函数时,请确保您subscribe()使用它。


查看完整回答
反对 回复 2022-01-01
?
慕标琳琳

TA贡献1830条经验 获得超9个赞

订阅后才会命中API


像这样尝试:


  deleteObjective(): void {

    if (confirm('Are you sure you want to delete this objective? This cannot be un-done.')) {

      if (this.objective.id !== 0)

        this.service.deleteObjective(this.objective.id).subscribe(res => {

          for (var i = 0; i < this.objectives.length; i++) {

            if (this.objectives[i] === this.objective) {

              this.objectives.splice(i, 1);

            }

          }

        })

    }

  }


查看完整回答
反对 回复 2022-01-01
  • 2 回答
  • 0 关注
  • 202 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号