Home > OS >  Angular How to Trigger a Button after another button is clicked
Angular How to Trigger a Button after another button is clicked

Time:12-06

In my code, I have two buttons. One for saving an offer and the other one for sending that offer. I want the send button to start to work if the save button is clicked one time. If the user tries to send the offer without clicking the save button at least once, a warning message should be displayed. Here is my code, how can I achieve this?

       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);
                });
            }
        });
      }

CodePudding user response:

Create a bool flag and manage it to check the state:

  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);
            });
        }
    });
}
  • Related