I am using mat-autocomplete, from the dropdown when manually one of the option is selected, the selected item is indicated with different bg color and a checkmark on right side.
But when one of the dropdown item is pragmatically set, the item is not highlighted. I use setValue() to programmatically to set the value.
1- Add a new property to your data model like:
2- Add the
[displayWith]property tomat-autocompleteto work with the function that helps us to set/get value to mat-option3- Use a function to bind data to mat autocomplete
fetchedData is the default value e.g.
this.fetchedData = "Four"4- Add ngClass to mat-option
then
5- Now the option that already had data has a new style. finally if want to add a checkbox to your option just use the material checkbox in the mat-option tag.
6- Finally you should change
optionsobjectisSelectedvalue totrue | falseto manage ngClass changes. use(optionSelected)='method($event)'onmat-autocompleteto changeoptionsobject property value.