1

I want to preselect a value in my select but there is nothing, why is this?

Plnkr

angular.module('selectExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
    $scope.cardSelect = [
      {name:'black', shade:'dark'},
      {name:'white', shade:'light'},
      {name:'red', shade:'dark'},
      {name:'blue', shade:'dark'},
      {name:'yellow', shade:'light'}
    ];
    $scope.card = $scope.cardSelect[2]; // red
  }]);
halfer
  • 19,824
  • 17
  • 99
  • 186
Mercer
  • 9,736
  • 30
  • 105
  • 170

1 Answers1

3

use ng-options instead of ng-repeat

<select data-ng-model="card" ng-options="card.name for card in cardSelect">

here is the plunker

Kalhan.Toress
  • 21,683
  • 8
  • 68
  • 92
  • Probably worth pointing out why the original didn't work. The value of each option was the shade property but the value on the scope was the third card object which isn't equal to just the shade property. – DoctorMick Dec 15 '14 at 13:07