我想使用ng-options
使用AngularJS select
,但它看起来不像我想的那样......
app.controller("LinkController", function($scope, $http, $filter) {
$http.get('/api/link').success(function(data, status, headers, config) {
$scope.pages = data.pages;
});
});
<div ng-controller="LinkController">
<div class="form-group">
<label for="page" class="control-label">Pages ({{pages.length}} pages)</label>
<select id="page" class="form-control" ng-options="page.title for page in pages">
<option value="">-- Please, select at least one page --</option>
</select>
</div>
</div>
问题:我没有选项,但pages.length
显示5
屏幕($ scope.pages):
答案 0 :(得分:2)
ng-options
directive requires ng-model
指令与它在一起。
添加ng-model
将解决问题。
答案 1 :(得分:0)
在您的选择中使用ng-model或尝试:
<div ng-controller="LinkController">
<div class="form-group">
<label for="page" class="control-label">Pages ({{pages.length}} pages)</label>
<select id="page" class="form-control">
<option value="">-- Please, select at least one page --</option>
<option ng-repeat="page in pages">{{page.title}}</option>
</select>
</div>
</div>