You can use @ViewChild directive to access elements in the view directly. Let’s take input element with a reference,
1 | <input #uname> |
and define view child directive and access it in ngAfterViewInit lifecycle hook:
1 2 3 4 5 | @ViewChild('uname') input; ngAfterViewInit() { console.log(this.input.nativeElement.value); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.