如何设置NG选项preselected价值? [英] How to set preselected value in ng-option?
本文介绍了如何设置NG选项preselected价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应该在下拉列表中选择城市ID,但我不能老是设法preSELECT它。我应该指令选择它或有任何其他方式?
<选择NG模型=cityIdNG选项=city.name城市在城市>< /选择>
解决方案
编辑NG-选项是:
city.id作为city.name城市在城市
如果您获取城市和不知道的ID
你可以在你的JavaScript函数的成功说(它返回城市):
$ scope.cityId = the_cities [0] .ID
设置为第一选择
否则你可能只是说:
$ scope.cityId = 1; //或存在什么
I have id from the city that is supposed to be selected in dropdown list, but I can`t manage to preselect it. Should I select it from directive or is there any other way?
<select ng-model="cityId" ng-options="city.name for city in cities"></select>
解决方案
Edit your ng-options to this:
city.id as city.name for city in cities
if you fetch the cities and don't know the ID's you could say in your javascript success function (which returns the cities):
$scope.cityId = the_cities[0].ID
to set the first as selected Else you could just say:
$scope.cityId = 1; //or anything that exists
这篇关于如何设置NG选项preselected价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文