-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[QUESTION] initial value with server-side lookup #129
Comments
@stanislasdrg for the initial value to work (and for setting any therefore you need to make sure that there initially exists an option with value |
Thank you for your reply. This situation arose, because I am looking for countries using a third party API, but the user has his own country object that is retrieved from my backend. The 3rd party API I use returns a complex object, as a result I am only backing 'part' of the object on my server. The consequence is that I will also have to write a method that uses my user's country object to find the index of the object having the same name in my Is my thinking correct here ? Many thanks for your help. Much appreciated. |
I would not compare object references for equality, but rather an id, e.g. compareWith = (a: Country, b: Country) => a && b && a.isoCode === b.isoCode; then you can have <mat-option *ngFor="let country of countries" [value]="country"> and setValue(userCountry) the only thing that needs to match is the isoCode. |
Hello,
first of all thank you for the awesome lib.
I know the question has been asked multiple times here, and I have looked at each and every question, but no matter what I do, I cannot set the initial value on the input.
Let me explain :
I am trying to have a value displaying in the input on application start, in exactly the same fashion as the 1st example of the provided Stackblitz.
However, I am using server side lookup and the async pipe. So, basically what I want to achieve is mixing example 1 and 5.
When I set the value, nothing happens. I have tried multiple different ways, to no avail.
Here is what my code looks like :
userPersonalInformation.country
is a country object that is retrieved on app load.It can have a value if the user selected a value in the past, otherwise no value will be set.
The main difference is that I am handling search in a fully reactive way, meaning I leave the async pipe subscribing to my observable :
I have read in the different questions, that
setValue()
should be passed an array with an index selected. This approach did not work either.I have tried doing a very basic thing in the Stackblitz and could not get it to work either.
How can I achieve such a behaviour ?
The text was updated successfully, but these errors were encountered: