Search code examples
angularjsng-options

ngOptions with Objects won't populate


I have a select dropdown I'd like to populate with the names of users in objects:

        <select id="entityDropDown" 
            ng-model="selectedUser" 
            ng-options="user as user.name for user in users" 
            ng-change="getUserInfo(selectedUser)">
        </select>

My object is structured as such:

users:  { 
    1:  { 
        name: Demo Administrator,
        id: 1,
        domain: null,
        email: null,
        isAdmin: False,
     },
    4:  { 
        name: ITUN\WSS,
        id: 4,
        domain: i:0#.f|admembers|,
        email: ,
        isAdmin: False,
    } 
}

Solution

  • Try using the comprehension expression for objects:

    ng-options="user as user.name for (key,user) in users"