suchen

Heim  >  Fragen und Antworten  >  Hauptteil

angular.js - AngularJS Select默认值?

AngularJS Select绑定的是对象:

$scope.cars = {
car01 : {brand : "Ford", model : "Mustang", color : "red"},
car02 : {brand : "Fiat", model : "500", color : "white"},
car03 : {brand : "Volvo", model : "XC90", color : "black"}
};
<select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars"></select>

现在想给select一个默认值怎么设置呢?

天蓬老师天蓬老师2810 Tage vor567

Antworte allen(2)Ich werde antworten

  • 世界只因有你

    世界只因有你2017-05-15 17:09:59

    <select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars>
    </select>
    $scope.selectedCar = $scope.cars.car01;

    这样就是默认选中第一项

    Antwort
    0
  • 漂亮男人

    漂亮男人2017-05-15 17:09:59

    <option>--please select--</option>

    Antwort
    0
  • StornierenAntwort