Angular单击另一个按钮后如何触发按钮



在我的代码中,我有两个按钮。一个用于保存报价,另一个用于发送报价。如果单击保存按钮一次,我希望发送按钮开始工作。如果用户尝试在未单击保存按钮的情况下发送优惠,则应显示一条警告消息。这是我的代码,我该如何实现?

saveOffer() {
this._offerService.saveOffer(this.offer).subscribe(() => {
this._offerService.getOfferDetail(this.offer.OfferId);
});
}
sendOfferSupplier() {
this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
disableClose: false
});
this.confirmDialogRef.componentInstance.confirmMessage = 'Do you want to send the offer?';
this.confirmDialogRef.afterClosed().subscribe(result => {
if (result) {
this.offer.ApprovementInfo.Description = result;
this._offerService.sendOfferSupplier(this.offer).subscribe(() => {
this._offerService.getOfferDetail(this.offer.OfferId);
});
}
});
}

创建一个bool标志并对其进行管理以检查状态:

isOfferSaved = false;
saveOffer() {
this._offerService.saveOffer(this.offer).subscribe(() => {
this._offerService.getOfferDetail(this.offer.OfferId);
this.isOfferSaved = true;
});
}
sendOfferSupplier() {
if(!this.isOfferSaved) {
//Show warning message with a toast component
alert('No offer saved yet!');
return;
}
this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
disableClose: false
});
this.confirmDialogRef.componentInstance.confirmMessage = 'Do you want to send the offer?';
this.confirmDialogRef.afterClosed().subscribe(result => {
if (result) {
this.offer.ApprovementInfo.Description = result;
this._offerService.sendOfferSupplier(this.offer).subscribe(() => {
this._offerService.getOfferDetail(this.offer.OfferId);
});
}
});
}

最新更新