ng-mat-select-infinite-scroll
ng-mat-select-infinite-scroll copied to clipboard
pre selected value
hi ,
after set value of mat-select , no pre-selection is visible.could you help with this issue
@barigo the reason it's not working, is that the selected value might not have been loaded as part of the limit and as such, will not be picket up by.
i got around this by injecting a static mat-option at the top of the list to appear as the selected option, and the rest of the infinite scroll following that. i don't have an example at hand at the moment, but it is pretty simple to implement, something like this:
public hasDefault = false;
// somewhere where you get the default value, set the hasDefault flag to true.
this.hasDefault = this.data.item; // as an example, this.data.item contains the item I'm passing to a modal
then in the HTML you can do something like this:
<mat-option *ngIf="hasDefault" [value]="defaultItem.id">{{ defaultItem.caption }}</mat-option>
seeing that the option is now visible to the engine, it'll select that as the default until the value is changed
note, this is just a rough example and can be updated to fit your scenario. hope this helps.