Query:
Is there a way to display a pre-selected item from my dropdown using its unique ID?
Issue/Explanation:
The dropdown options in my web service are dynamically fetched based on a user's ZipCode. For example, a Provider is displayed as {Phone: "5093240817", sp_id: "1", Name: "John Doe" … }. The user picks a name from the dropdown, but only the ID is stored. Now, when the user revisits to change their provider, I need to show the original Provider's Name using just the ID.
Note: Storing the value of Name isn't feasible because the web service can alter the name.
Proposed Solution:
My approach was to "filter" the array of Providers based on the original ID and retrieve the name in this manner. However, being new to Angular and TypeScript, I'm facing difficulties...
Approach Taken:
I came across an SO post where they addressed a similar issue, but I'm still struggling to comprehend it thoroughly. (How do I filter an array with TypeScript in Angular 2?)
const showValue = this.serviceProvider.filter(sp_id =>
this.selectedAppointment.sp_id)
**this.selectedAppointment.sp_id stores the original ID value.
Service Providers Options
{Phone: "5093240817", sp_id: "1", Longitude: -77.3841197, Provider Type: "Pediatric", Latitude: 38.9808589,Name: "John Doe" …}
1
{Phone: "097420454", sp_id: "3", Longitude: -77.3898602, Provider Type: "Pediatric", Latitude: 38.914697200000006, Name: "Kim" …}
2