nameList includes [“Julia”, “Evan”, “Tomas”];
select ng-model=“names” ng-options=“x for x in nameList”
In my controller, I make a service api call to GetNameByID/{id}”
and based on the id
, I need to set the default value of the dropdown menu in the modal form.
For example, if a user clicks on ID
1, the dropdown should display Julia by default.
The issue arises within the service call when I try to initialize the model with $scope.names = data
. Instead of selecting Julia, it adds an empty option at the top. Even though console.log(data)
prints “Julia”, it shows as
<option value=“?”></option>
Any suggestions on how to resolve this problem?