2016-07-25 87 views
0

我想將數據從數據庫填充到網頁中。不過,我似乎無法使這項工作:Angular JS ng-repeat沒有顯示選項

<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> 

下面是控制器

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

     } 

     </script> 

在選擇框它顯示{{options}},而不是值的JavaScript。

+0

什麼是不工作?你沒有看到選項列表嗎? – Filype

+0

爲什麼不使用'ng-options'? – Roope

回答

2

您錯過了控制器功能的右括號,這就是爲什麼您看不到該值。

據我所知它者優先使用NG選項與NG-模型一起,請參閱Choosing between ngRepeat and ngOptions知道好處

var analyzer=angular.module('analyzer',[]); 
 
     
 
analyzer.controller('AnalyzerController', function($scope) 
 
{ 
 
\t $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>

+0

謝謝。祝你好運! –

+0

@SamWilson不要忘記標記阿卜杜勒的答案是正確的。 – kefir500