我有以下自动生成的代码 (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贡献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);
}
}
})
}
}
添加回答
举报
0/150
提交
取消
