无法使用AngularJS中的List绑定下拉列表:
<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'}];
});
答案 0 :(得分:1)
使用正确的对象尝试使用正确的$scope
名称,而JavaScript中的对象名称区分大小写。检查此runnable fiddle demo并将其与您的解决方案进行比较。
app.controller('myCtrl', function($scope) {
$scope.list = [{
id: 1,
name: 'name 1'
},{
id: 2,
name: 'name 2'
}
];
});
<select>
<option ng-repeat="x in list" value="x.id">{{x.name}}</option>
</select>
答案 1 :(得分:0)
尝试这样做:
Json对象错了:
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>