I am trying to capture both the key and value from a <select>
element using ng-options with an object. Currently, my ng-model captures only the selected object, but I also need to capture the key that was selected. Here is the HTML snippet I'm working with:
<select class="form-control" id="xaxis" ng-model="model.xaxis" ng-options="k for (k,v) in model.options"></select>
Here is a sample of the model.options object in this scenario:
$scope.model.options = {
"power":{"label":"blah","values":[],"color":"red"},
"voltage":{"label":"blah","values":[],"color":"blue"}
}
Currently, when I select "power", my ng-model
variable becomes
{"label":"blah","values":[],"color":"red"}
. However, I also want to capture the key "power"
as a separate scope variable. Is there a way to achieve this?