Created
October 8, 2020 18:25
-
-
Save JeffryGonzalez/0c3bc63650e567b825adbadf5119bc2e to your computer and use it in GitHub Desktop.
for tyler
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, ElementRef, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[appNumberFilter]' | |
}) | |
export class NumberFilterDirective { | |
invalidChars = [ | |
'-', | |
'+', | |
'e', | |
]; | |
constructor(private elementRef: ElementRef) { } | |
@HostListener('keydown', ['$event']) onKeyDown(evt: KeyboardEvent): void { | |
if (this.invalidChars.includes(evt.key)) { | |
evt.preventDefault(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment