藍山帝景
2022-01-01 20:32:47
我有以下自動生成的代碼 (NSwag Studio) - 唯一的修改是withCredentials我為 Windows Auth(內(nèi)網(wǎng)應用程序)添加的代碼。 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_); })); }生成的服務中的其他一切工作正常(這是唯一的刪除),但這實際上沒有發(fā)送任何流量 - 在 Chrome 網(wǎng)絡拉出(F12)中,沒有對 API 的調(diào)用,API 也沒有收到任何內(nèi)容。我從我的組件中調(diào)用它,如下所示: 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 請求之前,它會調(diào)用它。控制臺中沒有錯誤。有任何想法嗎?我是 angular 的新手,但對編程很老。
2 回答

慕標琳琳
TA貢獻1830條經(jīng)驗 獲得超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
提交
取消