From 0a85777b4d9cb985c3ac94dd73aa15f12a6759d4 Mon Sep 17 00:00:00 2001 From: Aleksandr Pasevin Date: Fri, 19 Jun 2020 13:37:39 +0300 Subject: [PATCH] Fixes #293 --- projects/ngx-intl-tel-input/package.json | 2 +- .../directives/native-element-injector.directive.ts | 12 ++++++++---- .../src/lib/ngx-intl-tel-input.validator.ts | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/projects/ngx-intl-tel-input/package.json b/projects/ngx-intl-tel-input/package.json index 3bd2e203..5a805322 100644 --- a/projects/ngx-intl-tel-input/package.json +++ b/projects/ngx-intl-tel-input/package.json @@ -1,6 +1,6 @@ { "name": "ngx-intl-tel-input", - "version": "2.4.1", + "version": "2.4.2", "peerDependencies": { "@angular/common": "8.x - 9.x", "@angular/core": "8.x - 9.x", diff --git a/projects/ngx-intl-tel-input/src/lib/directives/native-element-injector.directive.ts b/projects/ngx-intl-tel-input/src/lib/directives/native-element-injector.directive.ts index 56096a4a..bb9fdf61 100644 --- a/projects/ngx-intl-tel-input/src/lib/directives/native-element-injector.directive.ts +++ b/projects/ngx-intl-tel-input/src/lib/directives/native-element-injector.directive.ts @@ -11,12 +11,16 @@ https://stackoverflow.com/a/54075119/1617590 */ @Directive({ // tslint:disable-next-line: directive-selector - selector: '[formControlName]', + selector: '[ngModel], [formControl], [formControlName]', }) export class NativeElementInjectorDirective implements OnInit { - constructor(private el: ElementRef, private control: NgControl) {} - + constructor( + private controlDir: NgControl, + private host: ElementRef + ) {} ngOnInit() { - (this.control.control as any).nativeElement = this.el.nativeElement; + if (this.controlDir.control) { + this.controlDir.control['nativeElement'] = this.host.nativeElement; + } } } diff --git a/projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.validator.ts b/projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.validator.ts index 3c457f38..645170ab 100644 --- a/projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.validator.ts +++ b/projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.validator.ts @@ -15,7 +15,9 @@ export const phoneNumberValidator = (control: any) => { } // Find inside injected nativeElement and get its "id". const el: HTMLElement = control.nativeElement as HTMLElement; - const inputBox: HTMLInputElement = el.querySelector('input[type="tel"]'); + const inputBox: HTMLInputElement = el + ? el.querySelector('input[type="tel"]') + : undefined; if (inputBox) { const id = inputBox.id; const isCheckValidation = inputBox.getAttribute('validation');