实施ng-options

时间:2016-11-14 11:01:46

标签: angularjs ng-options

我想从下面的

中显示A abd B作为我的选项列表
$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尝试这样

<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>

1 个答案:

答案 0 :(得分:0)

你可以这样,

<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