我有一個處理檔案上傳的 Angular 介面,在提交按鈕之后,它將這個檔案保存在 MySQL 資料庫中。我想在此提交方法中進行另一個呼叫,但第二個 http 呼叫需要該id物體的持久化(檔案),我不知道如何從上傳的該檔案中檢索該特定 id。
這是我的提交方法:
onSubmit() {
const statementFile = new StatementFile();
// *******
// here are some business logic
// *******
// this will send POST request and save it to MySQL.
this.statementFileService.postStatementFile(statementFile).subscribe(
{
next : (response) => {
alert('You have been submitted your statement file, check MySQL');
},
error: (err) => {
alert(`there was a problem: ${err.message}` );
}
}
);
// this is the second http request I want to call but it needs particularly the id of that statementFile uploaded.
this.activitiWorkflowService.createPreccess(statementFile.statementFileId).pipe(takeUntil(this._unsubscribeAll), debounceTime(3000)).subscribe(
(data: any) => data
);
}
這是我的 StatementFile 類:
export class StatementFile{
statementFileId: number;
dateReception: Date;
label: string;
}
uj5u.com熱心網友回復:
您可以使用 switchMap 運算子鏈接請求。statementFile.statementFileId 或 response.statementFileId 或 postStatementFile 請求中的其他內容,您將使用它來呼叫下一個請求。
this.statementFileService.postStatementFile(statementFile)
.pipe(
switchMap(response => this.activitiWorkflowService.createPreccess(statementFile.statementFileId).pipe(takeUntil(this._unsubscribeAll)))
)
.subscribe({
next : (data: any) => data,
error: (err) => {
alert(`there was a problem: ${err.message}` );
}
}
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/479503.html
標籤:javascript 爪哇 有角度的 春天 打字稿
上一篇:比較Haskell中的串列串列
