0 votes
in Angular by
How do you choose an element from a component template?

1 Answer

0 votes
by

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);
}

Related questions

0 votes
asked Jul 10, 2023 in Angular by Robindeniel
0 votes
asked Dec 15, 2023 in Angular by AdilsonLima
...