Skip to content

Instantly share code, notes, and snippets.

@JeffryGonzalez
Created October 8, 2020 18:25
Show Gist options
  • Save JeffryGonzalez/0c3bc63650e567b825adbadf5119bc2e to your computer and use it in GitHub Desktop.
Save JeffryGonzalez/0c3bc63650e567b825adbadf5119bc2e to your computer and use it in GitHub Desktop.
for tyler
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