搜尋

首頁  >  問答  >  主體

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一個預設值怎麼設定呢?

天蓬老师天蓬老师2839 天前588

全部回覆(2)我來回復

  • 世界只因有你

    世界只因有你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;

    這樣就是預設選取第一項

    回覆
    0
  • 漂亮男人

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

    <選項>--請選擇--

    回覆
    0
  • 取消回覆