1

I have implemented a drop down where i m trying to populate my drop down from database using ng-options but when the data comes it comes in a object which don't have key or value as you can see in image below.I have tried to use ng options as:- by using ng-option

<tr>
<td nowrap>Billing Method:</td>
<td>
<select id="listBillingMethod" data-ng-options="blngmthod as blngmthod for blngmthod in listBillingMethod"  ng-model="custom.listBillingMethod" style="width: 182px !important; height: 34px;"></select>
</td>
<td nowrap></td>
 <td></td>
</tr>

If i am trying to do the same using ng-repeater it gives me results as i want,i.e my dropdown will populated up.My ng-repeater code:-

 <tr>
 <td nowrap>Billing Method:</td>
 <td>
 <select id="listBillingMethod" style="width: 182px !important; height: 34px;">
 <option value="0">--- Select an option ---</option>
 <option data-ng-repeat="blngmthod in listBillingMethod">{{blngmthod}}</option>
</select>
</td>
<td nowrap></td>
<td></td>
</tr>

My data comes in form of:- Data Image

1 Answer 1

1

look at this fiddle you should really use ng-options if ur Data Object has no keys than modify it so it fits for the ng-options example

fiddle

<form>        
    <select ng-model="group" 
        ng-options="o.value as o.label for o in myGroups"
        ng-change="tellUs()"/>       
</form>  
Sign up to request clarification or add additional context in comments.

7 Comments

I have seen you fiddle but there you know the name of key and value here i am getting my key or value as you can see in the above image.
ah i forget to include this link stackoverflow.com/questions/20392678/… this explains how to use ng-options, with a datasource
I have one more question how can i pass the index value on ng change to a function so that i can process further..Means i want to check the index of my dropdown and than based upon its index my function will go to my API get the data accordingly and return the same. Is there any way to set a default value with index 0 as Select Option or something..
i found this for your index problem jsfiddle.net/EyBVN/28 with index.Of you can get the desired index of your object when that object is selected the binded scope.value is getting updated
in your example you could get index.Of blngmethod in your ng-change function this should work
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.