简体   繁体   中英

AngularJs dropdown with ng-repeat

I'm trying to create a dropdown list from an angular controller: My html code:

  <select>
  <option value="" disabled selected >Choose your option</option>
  <option ng-repeat="ty in type">{{ty.$value}}</option>
  </select>

Controller code:

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

In this case it works:

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

The ty.$value works in above code, but in this <select> tag doesn't show anything any idea why is that?

You don't need to use ng-repeat , you can use ng-options

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

Use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM