Angular js ng-options不起作用

时间:2015-03-27 22:09:39

标签: javascript angularjs

我正在尝试使用ng-options,但似乎没有工作,我一直在阅读和阅读有关该主题的内容,并且我有相同的结构,但我得到了相同的结果,希望你伙计们可以帮助我。

HTML:

<div ng-app>
  <div ng-controller="myCtrl">
    <select ng-options="person.name for person in people">
    </select>
  </div>
</div>

JS:

function myCtrl($scope) {
      $scope.people = [
        { name: "My domain" },
        { name: "qe" },
        { name: "contact_base_esp" },
        { name: "Domain 1" },
        { name: "Domain 2" },
        { name: "this is a template" },
        { name: "Contact base esp" }
    ];
}

小提琴: http://jsfiddle.net/5DMjt/1005/

1 个答案:

答案 0 :(得分:0)

您错过了几位,请参阅下面的演示

angular.module("app", []).controller("myCtrl", myCtrl);

function myCtrl($scope) {
  $scope.people = [{
    name: "My domain"
  }, {
    name: "Cobranza"
  }, {
    name: "contact_base_esp"
  }, {
    name: "Domain 1"
  }, {
    name: "Domain dos"
  }, {
    name: "Este es un template"
  }, {
    name: "Contact base esp"
  }];

  $scope.selected = $scope.people[0];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
  <div ng-controller="myCtrl">

    <select ng-model="selected" ng-options="person as person.name for person in people">
      <option value="Choose one"></option>
    </select>
  </div>
</div>