Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 使用ng重复选择中的预选选项_Angularjs - Fatal编程技术网

Angularjs 使用ng重复选择中的预选选项

Angularjs 使用ng重复选择中的预选选项,angularjs,Angularjs,当我使用ng repeat重复选项时,如何预选选项,如下所示: <select data-ng-model="info.country" ng-change="changeCountry()" name="country" required> <!-- <option selected disabled hidden value=''></option> --> <option data-ng-repeat="country in

当我使用ng repeat重复选项时,如何预选选项,如下所示:

<select data-ng-model="info.country" ng-change="changeCountry()" name="country" required>
<!-- <option selected disabled hidden value=''></option> -->
     <option data-ng-repeat="country in countries" value="{{country.id}}">{{country.countryName}}</option>
</select>

{{country.countryName}
data ng model
返回编号
3
,方法
ng change=“changeCountry()”
在其实现中使用相同的编号

我需要预选的项目是
3
,而不是
1
(这将减少1,因为它是一个数组,但我想你明白了)

我需要预先选择项目。这是可能的吗?怎样才能达到这样的结果


我通过使用
ng选项实现了这一点:

<select ng-options="country.id as country.countryName for country in countries" ng-model="info.country" ng-change="changeCountry()" name="country" required></select>
 <select data-ng-model="info.country" 
            ng-change="changeCountry()" name="country"             
            ng-options="c.id as c.countryName for c in countries"            
            required>

    </select>


ng repeat
on
id
转换为字符串。这就是它不起作用的原因

{“国家”:3}
vs
{“国家”:“3}

您可以使用
ng选项解决此问题

<select ng-options="country.id as country.countryName for country in countries" ng-model="info.country" ng-change="changeCountry()" name="country" required></select>
 <select data-ng-model="info.country" 
            ng-change="changeCountry()" name="country"             
            ng-options="c.id as c.countryName for c in countries"            
            required>

    </select>


你能分享一下
国家/地区吗
example@MaximShoustin-是的,这从根本上解释了问题。谢谢你的澄清!真是太好了。