Angular JS ng-repeat没有显示选项

时间:2016-07-25 08:51:13

标签: javascript angularjs model-view-controller

我正在尝试将数据从数据库填充到网页中。但是,我似乎无法做到这一点:

<div ng-controller="AnalyzerController">
    <select id="Listbox" ng-model="Listofoptions" style="width: 500px">                  
    <option ng-repeat="option in options" value="{{option}}"> {{option}} </option>
    </select></td></div>

这是控制器的javascript     

        <script>
        var analyzer=angular.module('analyzer',[]);
        analyzer.controller('AnalyzerController',function($scope )
        {
            $scope.options = ["A","B","C","D","E"];

        }

        </script>

在选择框中,它显示的是{{options}},而不是值。

1 个答案:

答案 0 :(得分:2)

您错过了控制器功能的右括号,这就是您没有看到值的原因。

AFAIK首选使用ng-options和ng-model,请参阅Choosing between ngRepeat and ngOptions以了解其益处

var analyzer=angular.module('analyzer',[]);
        
analyzer.controller('AnalyzerController', function($scope)
{
	$scope.options = ["A","B","C","D","E"];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="analyzer">
  <div ng-controller="AnalyzerController">
      <select id="Listbox" ng-model="Listofoptions" style="width: 500px">                  
        <option ng-repeat="option in options" value="{{option}}"> {{option}} </option>
      </select>
  </div>
</div>