Get native element of a form control in angular

From Code Trash
Jump to: navigation, search
@Directive({
    selector: '[ngModel], [formControl]', // or [formControlName] or input
})
//NgModel is optional. If NgModel is used then it can be included.
export class NativeElement {
    constructor(private el: ElementRef, private control : NgControl, @Optional() private model : NgModel) {
        if (!! model)
            (<any>model.control).nativeElement = el.nativeElement;
        else
            (<any>control).nativeElement = el.nativeElement;
    }
}

And then in the @ngModel declarations add NativeElement

https://stackoverflow.com/a/49462046/389432