gvhuyssteen
gvhuyssteen

Reputation: 292

Cannot pre-select last option in Ionic Select

Here is the Codepen:

http://codepen.io/dagert/pen/JXqVEz

On the Codepen you will find two select boxes. One with the second last option pre-selected and another one with the last option pre-selected.

The issue is that I cannot pre-select the last option in the drop down box.

angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope) {
 
  var values = [{"id":"84279ed396g5l6kj","name":"One"},{"id":"62d9lg85llek38j7","name":"Two"},{"id":"46327g3839elk5j9","name":"Three"},{"id":"8kj65g6536el47d2","name":"Four"},{"id":"46l38el98jg57d2k","name":"Five"},{"id":"7kd35g4k3lej698l","name":"Six"}];
  
  $scope.typeWorking = {
    "value": '46l38el98jg57d2k',
    "values": values
  };
  
   $scope.typeNotWorking = {
    "value": '7kd35g4k3lej698l',
    "values": values
  };
  
});
<html ng-app="ionicApp">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <title>Blank Starter</title>

    <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
    <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
    
  </head>
  <body ng-controller="MyCtrl">

    <ion-header-bar class="bar-positive">
      <h1 class="title">Blank Starter</h1>
    </ion-header-bar>

    <ion-content>
      
      <select ng-model="typeWorking.value" required>
          <option value=""></option>
          <option value="{{ name.id }}" ng-selected="name.id == name.value" ng-repeat="name in typeWorking.values">{{ name.name }}</option>
        </select>
     
            <select ng-model="typeNotWorking.value" required>
          <option value=""></option>
          <option value="{{ name.id }}" ng-selected="name.id == name.value" ng-repeat="name in typeNotWorking.values">{{ name.name }}</option>
        </select>
      
    </ion-content>

  </body>
</html>

Upvotes: 0

Views: 183

Answers (1)

Boris Savic
Boris Savic

Reputation: 781

You have error in your code, name.id == name.value should be name.id == typeNotWorking.value

<option value="{{ name.id }}" ng-selected="name.id == typeNotWorking.value" ng-repeat="name in typeNotWorking.values">{{ name.name }}</option>

Upvotes: 1

Related Questions