Search code examples
angularjsng-optionsangularjs-ng-options

Ng-options doesn't work


I'd like to use ng-options for my select using AngularJS but it seems not working as I'd like...

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>

Issue : I get no options, but pages.length is showing 5

Screen ($scope.pages) :

enter image description here


Solution

  • ng-options directive requires ng-model directive to be there with it.

    Adding ng-model will fix the problem.