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.....
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.
Janarthanan SPosted Jun 2, 2023, 2:29 AM
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.Rajkiran SwainPosted Jun 1, 2023, 6:25 PM
Rajesh GamiPosted Jul 18, 2022, 6:40 AM
Rijwan AnsariPosted Mar 4, 2022, 6:33 AM
AkshayPosted Feb 9, 2022, 7:21 AM
Sachin SinghPosted Feb 7, 2022, 2:51 PM