Search code examples
angularjsng-options

implementation of ng-options


i want to show A abd B as my options list from the below

$scope.devices={
    "A": {
        "status": 3,
        "event": "Door was opened",
        "name": "xxxxxx ",
        "latlng": "xxxxx"
    },

    "B": {
        "status": 4,
        "event": "kitchen was opened",
        "name": "xxxxx ",
        "latlng": "xxxxx"
}
}

iam trying like this

<select ng-change="selected(prop)" style="color:black;" ng-model="prop" ng-options="item as item for item in devices">
                            <option value="">-- choose an option --</option>
                        </select>

Solution

  • You can have like this,

    <label for="reason">Device</label>
       <select ng-change="selected(Device)" ng-model="Device" ng-options="key as key for (key , value) in devices"></select>
    </div>
    

    DEMO