Forked from svetlio/no-dbl-click-mat.directive.ts
Created
September 11, 2018 08:16
-
-
Save Yurii-Chaban/1f29eecf35d2b6cf59aee3e52f11a345 to your computer and use it in GitHub Desktop.
Angular 5 directive - Prevent double click for html button (no-dbl-click.directive.ts), and material mat-button (no-dbl-click-mat.directive.ts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[appNoDblClickMat]' | |
}) | |
export class NoDblClickDirectiveMat { | |
constructor() { } | |
@HostListener('click', ['$event']) | |
clickEvent(event) { | |
event.srcElement.parentElement.setAttribute('disabled', true); | |
setTimeout(function(){ | |
event.srcElement.parentElement.removeAttribute('disabled'); | |
}, 1000); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[appNoDblClick]' | |
}) | |
export class NoDblClickDirective { | |
constructor() { } | |
@HostListener('click', ['$event']) | |
clickEvent(event) { | |
event.srcElement.setAttribute('disabled', true); | |
setTimeout(function(){ | |
event.srcElement.removeAttribute('disabled'); | |
}, 500); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment