Angular 2 get Input element value
I created a plnkr link: https://plnkr.co/edit/49TEP8lB4lNJEKsy3IDq?p=preview
It works for me so probably you may want to create your own plnkr so ppl can help
export class ApiDemoApp{ root = ApiDemoPage; @ViewChild('myname') input:ElementRef; constructor() { } ngAfterViewInit() { console.log(this.input.nativeElement.value); }}
Use this code
@ViewChild('myname') input:any; ngAfterViewInit() { console.log(this.input.nativeElement.value) ; }
If you using DirectiveTry this way:
private el: HTMLInputElement;constructor(private _elementRef: ElementRef) { this.el = this._elementRef.nativeElement;}ngOnInit(): void { console.log(this.el.value);}