0

I have items as my json object which contains some data which i want to show on dropdown list.
But still it is showing my dropdown list as blank.
Here i am using ng-repeat.
I have listed my code here.
HTML :

<div ng-controller="Ctrl">   
    <div ng-repeat="item in items">
        <select ng-model="item.shareToOption" ng-options="c.value for c in shareToOptions"></select>
    </div> 
<div>

JS:

var app = angular.module('app', []);

function Ctrl($scope) {
        $scope.items = [
            {
            "shareToOption" : {id:1,value:"AA1"}
            },
            {
            "shareToOption" : {id:2,value:"AA2"},
            },
            {
            "shareToOption" : {id:3,value:"AA3"},
            },
            {
            "shareToOption" : {id:4,value:"AA4"}
            }
        ];

        $scope.shareToOptions = [
            {id:1,value:"AA1"},
            {id:2,value:"AA2"},
            {id:3,value:"AA3"},
            {id:4,value:"AA4"},
            {id:4,value:"AA5"},
            {id:4,value:"AA6"},
            {id:4,value:"AA7"}
        ];
}
2
  • Please include the relevant parts of your code in your question. Commented Mar 13, 2014 at 8:51
  • The dropdown isn't blank. Please check Commented Mar 13, 2014 at 8:56

1 Answer 1

2

You should use the new track by expression for ng-options. Something like this:

<div ng-controller="Ctrl">   
    <div ng-repeat="item in items">
        <select 
          ng-model="item.shareToOption" 
          ng-options="c.value for c in shareToOptions track by c.id"
        ></select>
    </div> 
<div>

Make sure that you're using Angular 1.2.

Sign up to request clarification or add additional context in comments.

Comments

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.