这是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>
&#13;
答案 0 :(得分:1)
您的代码中存在错误,name.id == name.value
应为name.id == typeNotWorking.value
<option value="{{ name.id }}" ng-selected="name.id == typeNotWorking.value" ng-repeat="name in typeNotWorking.values">{{ name.name }}</option>