2

Can't bind dropdown with List in AngularJS:

<select>
    <option ng-repeat="x in list">{{x}}</option>
</select>

app.controller('myCtrl', function($scope) {
    $Scope.list=[{id:1, name='name 1'},{id:2, name='name 2'}];
});
1
  • you have a typo.. $scope not $Scope Commented Mar 15, 2017 at 11:58

2 Answers 2

1

Try it with a right object and use the correct name of $scope while object names are case sensitive in JavaScript. Check this runnable fiddle demo and compare it with your solution.

app.controller('myCtrl', function($scope) {
    $scope.list = [{
            id: 1, 
            name: 'name 1'
        },{
            id: 2, 
            name: 'name 2'
        }
    ];
});

view

<select>
    <option ng-repeat="x in list" value="x.id">{{x.name}}</option>
</select>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i think it should be "x.id" instead of "x.value"
0

try to do like this:

Json object was wrong:

app.controller('myCtrl', function($scope) {
        $scope.list=[{id:1, name:'name 1'},{id:2, name:'name 2'}];
    });

<select>
    <option ng-repeat="x in list">{{x.name}}</option>
</select>


Or, 

<select ng-model="selectedItem" ng-options="item for item in list">
</select>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.