Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre selected value #15

Open
barigo opened this issue Dec 25, 2020 · 1 comment
Open

pre selected value #15

barigo opened this issue Dec 25, 2020 · 1 comment

Comments

@barigo
Copy link

barigo commented Dec 25, 2020

hi ,

after set value of mat-select , no pre-selection is visible.could you help with this issue

@JadedEric
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants