0

I am creating a web app using mvc5 with angularjs,

i have a dynamic dropdownlist, i am fetching my data from my database,

my dropdownlist look like the following,

<select ng-model="mduser.dataindrop" class="form-control" ng-options="x as x.username for x in dataindrop" ng-change="change(mduser.dataindrop)"></select>

all is working fine except one thing,

i am not able to set initial value in my dropdownlis,

i want to set (select) as an initial value, but not able to succeed yet,

this is how my controller looks,

$scope.usernameindrop = function () {
                $http.get('/Web Service/dashboard.asmx/getusername', {
                    params: {
                        userid: $sessionStorage.userautoid
                    }
                }).then(function(response){
                    $scope.dataindrop = response.data;
                    console.log(response.data);
                })
            }

and this is my data in json

Array[3]
0
:
Object
$$hashKey
:
"object:23"
userid
:
"2f8e8bac-a631-4df3-8ab9-b0c293099bc6"
username
:
"new"
__proto__
:
Object
1
:
Object
$$hashKey
:
"object:24"
userid
:
"8ba0ae53-078d-4301-95eb-409acb1c92c6"
username
:
"b"

i just want to set (select as an initial value for my dropdownlist)

1 Answer 1

1

Try like this

<select ng-model="mduser.dataindrop"
 ng-options="x.userid as x.username for x in dataindrop"></select>

and in controller init model as this

$scope.mduser.dataindrop  = dataindrop[0].userid;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.