1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How to deal with double submit in Angular2

Discussão em 'Angular' iniciado por Daskus, Julho 1, 2025.

  1. Daskus

    Daskus Guest

    If I click fast on my submit-button the form is submitted two or more times. My thought was to prevent this with the disabled attribute, but I need variable disableButon in every form like this:

    @Component({
    selector: 'example',
    template: `
    <form (submit)="submit()" >
    <--! Some Inputs -->
    <button [disabled]="disableButton" type="submit">Submit<button>
    </form>
    `
    })
    export class ExampleComponent {
    private disableButton: boolean = false;
    .......
    submit(){
    this.disableButton = true;
    /*
    * API call
    */
    this.disableButton = false;
    }
    }


    Am I doing this right or is there a more efficent/elegant way to do it?

    Continue reading...

Compartilhe esta Página