summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts')
-rw-r--r--vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts19
1 files changed, 8 insertions, 11 deletions
diff --git a/vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts b/vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts
index dada09bef..d00c52502 100644
--- a/vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts
+++ b/vid-webpack-master/src/app/shared/directives/inputPrevention/inputPreventionPattern.directive.ts
@@ -1,18 +1,10 @@
-import {Directive, ElementRef} from '@angular/core';
+import {Directive, ElementRef, HostBinding, HostListener} from '@angular/core';
@Directive({
- selector: '[patternInput]',
- host: {
- '(keypress)': 'onKeypress($event)'
- }
+ selector: '[patternInput]'
})
export class InputPreventionPatternDirective{
- inputElement : ElementRef;
- constructor(el: ElementRef) {
- this.inputElement = el;
- }
-
- onKeypress(event: KeyboardEvent) {
+ @HostListener('keypress', ['$event']) onKeypress(event: KeyboardEvent) {
const pattern = new RegExp(this.inputElement.nativeElement.pattern);
if(pattern){
if(!pattern.test(event['key'])){
@@ -21,4 +13,9 @@ export class InputPreventionPatternDirective{
}
return event;
}
+
+ inputElement : ElementRef;
+ constructor(el: ElementRef) {
+ this.inputElement = el;
+ }
}