2
我想设置China
所选择的国家,但不知何故,只在下拉创下了中国,如果我做的一样 - $scope.countrySelected = $scope.countryList[5];
选择下拉作为使用NG选项AngularJS值选择
让我知道,如果可能的话通过文本设置价值只有通过服务我得到China
作为一个文本,只有我需要匹配。
HTML代码 -
<select
ng-options="country.c_name for country in countryList track by country.c_id"
ng-model="countrySelected">
</select>
脚本代码 -
var myApp = angular.module('myApp', []);
myApp.controller('mainCtrl', function($scope){
$scope.countryList = [
{c_id: 1, c_name: 'Iran'},
{c_id: 2, c_name: 'Iraq'},
{c_id: 3, c_name: 'Pakistan'},
{c_id: 4, c_name: 'Somalia'},
{c_id: 5, c_name: 'Libya'},
{c_id: 6, c_name: 'China'},
{c_id: 7, c_name: 'Palestine'}
];
$scope.countrySelected = 'China';
})
工作Plnkr -http://plnkr.co/edit/6qSvuuOtJHVSoNWah0KR?p=preview
我相信它的ES6方法使应用支持IE9 – Nesh
@Nesh将不能在IE浏览,看看我的答案。我现在使用过滤方法。 –