I am working with a dropdown list that is populated from an API call. Here is my code snippet:
<label>User Code:</label>
<select ng-options="c as c.User for c in userList"
ng-model="selectedUser" id="search3">
</select>
To fetch the data for the dropdown, I have created a directive function as follows:
scope.getAllUsers = function(){
scope.userList = [];
ApiServices.getAllUsers().then(function (response) {
scope.userList = response.data;
});
}
scope.getAllUsers();
Now, I want to pre-select a user with the User Code: SS1234
when the page loads. I am considering using the selected
attribute but unsure how to apply it to the fetched data.