Currently in my Angular application, I have hardcoded values in an array and bound them to a dropdown list using the in-built control, which is functioning correctly. The current setup looks like this:
export class UserDetailsComponent implements OnInit {
constructor(private _userManagemement: UserManagementService){
}
userDetails : IUserDetails = {
selectedValue: 'tim435'
items: [
{
text: 'tim hoppins',
value: 'tim435',
id: 12
},
{
text: 'andrew ramos',
value: 'and71',
id: 18
},
{
text: 'jay ronne',
value: 'jr214',
id: 21
}
]
};
}
Now, my goal is to dynamically fetch details from the database instead of hardcoding them in the code. To achieve this, I have created an API and a method in the service that calls the endpoint like this:
export class UserManagementService {
public getUserDetails() {
return this.httpClient.get('endpoint');
}
}
However, I am unsure of how to bind the data returned by the getUserDetails()
method in the service to the items array of my userDetails
object.