AngularJs下拉列表中使用ng-repeat

AngularJs dropdown with ng-repeat

本文关键字:ng-repeat 下拉列表 AngularJs      更新时间:2023-09-26

我试图从一个角控制器创建一个下拉列表:html代码:

  <select>
  <option value="" disabled selected >Choose your option</option>
  <option ng-repeat="ty in type">{{ty.$value}}</option>
  </select>
控制器代码:

var typeRef = new Firebase(FIREBASE_URL + "/type");
var typeArray = $firebase(typeRef).$asArray();
typeArray.$loaded().then( function (data) {
            $scope.type = data;
            console.log(data);
        });

<ul id='dropdown2' class='dropdown-content'>
<li ng-repeat="ty in type"><a href="#!">{{ty.$value}}</a></li>
</ul>

ty.$value在上面的代码中工作,但是在这个<select>标签中没有显示任何东西,任何想法为什么是这样?

您不需要使用ng-repeat,您可以使用ng-options

<select ng-options="ty.$value for ty in type" ng-model="something">
<select>

使用

<select ng-options="ty.$value as ty.$value for ty in type" ng-model="achvtype"> <option value="" disabled selected >Choose your option</option> </select>

http://jsbin.com/juhamul/edit?html、js、输出