1.

How do you choose an element from a component template?

Answer»

To directly access items in the view, use the @ViewChild directive. Consider an input item with a reference.

<input #example>

and construct a view child directive that is accessed in the ngAfterViewInit lifecycle hook

@ViewChild('example') input;

ngAfterViewInit() {
console.log(this.input.nativeElement.value);
}


Discussion

No Comment Found