Hii
I'm facing one problem while saving the data. what actually happening is like on save button , if i click at the same time for multiple times (e.g Double click or more) then my data is getting saved more than once.
How can i prevent saving data for multiple time by preventing button click for more than once.
here is my code.....
Code
Save
C#
save(param) {
this.isInProgress = true;
// code for saving the data into multiple tables
this.isInProgress = false; // after successfull save set this.isInProgress = false
}any help would be appretiated.
thank you.

Rajesh GamiRank #30 · 41.5K reputationPosted Jul 18, 2022, 2:40 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Feb 7, 2022, 9:51 AM EST
Akshay108 reputationPosted Feb 9, 2022, 2:21 AM EST
Rijwan AnsariRank #82 · 24.2K reputationPosted Mar 4, 2022, 1:33 AM EST
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 1, 2023, 2:25 PM EDT
isButtonClicked = false; save(param) { if (!this.isButtonClicked) { this.isButtonClicked = true; this.isInProgress = true; // Code for saving the data into multiple tables // After successful save, you can set this.isInProgress = false // and enable the button again this.isInProgress = false; this.isButtonClicked = false; } }Janarthanan SRank #224 · 11K reputationPosted Jun 1, 2023, 10:29 PM EDT
TypeScript Code
import { Component } from '@angular/core';
@Component({
selector: 'app-your-component',
templateUrl: './your-component.component.html',
styleUrls: ['./your-component.component.css']
})
export class YourComponent {
isButtonDisabled = false;
handleButtonClick() {
this.isButtonDisabled = true;
// Perform your button click logic here
// If you want to re-enable the button after a specific duration, you can use setTimeout:
setTimeout(() => {
this.isButtonDisabled = false;
}, 3000); // Re-enable after 3 seconds (adjust the duration as per your requirement)
}
}
In the
handleButtonClickmethod, we setisButtonDisabledtotruewhen the button is clicked to disable it. You can add your custom logic inside the method to handle the button click.To re-enable the button after a certain duration (in this example, 3 seconds), you can use
setTimeoutto setisButtonDisabledback tofalse.