Highlight the initial value of angular autocomplete

54 views Asked by At

When providing a form control with an initial value, the mat-option is not selected by defaut in the mat-autocomplete dropdown:

Actual behavior Actual behavior

Desired behavior Desired behavior

https://stackblitz.com/edit/vemaxm-cynrcg?file=src%2Fexample%2Fautocomplete-auto-active-first-option-example.html,src%2Fexample%2Fautocomplete-auto-active-first-option-example.ts

I've tried to select the map-option using ref to the autocomplete and then in afterViewInit getting the QueryList of MatOption and calling the select() on the found one. But it triggers the changeDetection which lead to "ExpressionChangeAfterItHasBeenCheckedError". Any ideas how to solve this.

Thank you

0

There are 0 answers