兩者均可用於實現下拉列表,而且度娘上有不少關於二者的內容,此處再也不贅述,本文爲了說明在最近的項目中遇到的相關問題,
能夠寫成以下格式php
<select> <option value="x.id" ng-repeat="x in list" ng-bind="x.name"> </option> </select>
<select ng-options="x.id as x.name for x in list" ng-model="listId"> </select>
另:
附上在解決過程當中嘗試的方法,可能重複,有問題僅作記錄(如下簡寫,如下兩種方法都是使用ng-repeat)html
【步驟】:列表list中id類型規定爲number類型,首次實現頁面下拉框時,使用的是ng-repeat,
【結果】:下拉列表顯示爲空白
【問題】:F12查看Elements,發現下拉列表中option以下顯示django
<option value="? number:1 ?"></option>
【解決1】 在js中將id裝換爲string 類型list.id = list.id+"";
【方法的問題】
1.只是寫了一句話,可是須要的地方不少,致使重複....
2.改變了原類型spa
【解決2】 朋友的思路,在js中寫一個方法將id裝換爲string 類型,並在頁面上使用這個方法,具體以下:
.js:code
$scope.toString = function(){ list.id.toString(); }
.htmlxml
<option value="{{toString(x.id)}}" ng-repeat="x in list" ng-bind="x.name"></option>