2016-05-18 62 views
0

這裏是Codepen:不能預先選擇最後一個選項

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

在Codepen你會發現兩個選擇框。 一個預選第二個選項,另一個預選最後一個選項。

問題是我無法預先選擇下拉框中的最後一個選項。

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>

回答

1

你在你的代碼有錯誤,name.id == name.valuename.id == typeNotWorking.value

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