Reputation: 61
I have an object like this:
"choiceList":[{"1":"cash"},{"2":"credit"}]
I want to show this object in a select
element in which option
elements display cash and credit.
I have another variable in which I want to save 1 or 2 if either cash or credit is selected.
HTML:
<select name="memoType" ng-model="lookUpValue">
<option value="">--Please Choose--</option>
<option ng-repeat="(key,value) in list">{{value}}</option>
</select>
Upvotes: 0
Views: 2787
Reputation: 1182
Answer to your updated question
HTML:
<div ng-controller="ControllerA" ng-app ng-init="lookUpValue='0'">
Simple options<br/>
<select ng-options="k as v for (k, v) in list[0] " ng-model="lookUpValue">
</select><br/>
lookUpValue = {{lookUpValue}}<br/>
</div>
Controller:
function ControllerA($scope) {
$scope.list = [{"0":"--Please Choose--","1" : "Cash" , "2" : "Credit"}];
}
See complete working demo here
Upvotes: 0
Reputation: 4274
function ControllerA($scope) {
$scope.list= {"1" : "Cash" , "2" : "Credit"};
}
<div ng-controller="ControllerA" ng-app>
Simple options<br/>
<select ng-options="k as v for (k, v) in list" ng-model="lookUpValue">
</select><br/>
lookUpValue= {{lookUpValue}}
</div>
Upvotes: 1