本文介绍了角度:ng-select不显示ng-selected值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试根据id设置select的默认值.
Trying to set the default value in select depending on the id.
我有一个对象location
,其中<pre>{{location.routeId}}</pre>
打印一个id 819e41ef-0081-41e6-a415-2766dc16e8e4
I have a object location
where <pre>{{location.routeId}}</pre>
prints an id 819e41ef-0081-41e6-a415-2766dc16e8e4
<select ng-model="location.route">
<option value="" disabled>Choose Route</option>
<option ng-repeat="route in appData.Routes"
ng-selected="{{route.id == location.routeId}}"
value="{{route}}">
{{route.id}} : {{route.name}}
</option>
</select>
appData.Routes
中的route
具有参数name
和id
,我试图将route.id
与location.routeId
The route
inappData.Routes
has parameters name
and id
, I'm trying to match route.id
with location.routeId
如果我检查元素,则对于其中一个选项,我可以看到ng-selected
为true,但仍未在UI中选择它.
If I inspect element, I can seeng-selected
as true for one of the options, but still its not being selected in the UI.
这是UI的屏幕截图
推荐答案
尝试一下:
<select ng-model="location.route">
<option value="">Choose Route</option>
<option ng-repeat="route in appData.Routes"
ng-selected="route.id == location.routeId || location.route && route.id == location.route.id"
ng-value="route">
{{route.id}} : {{route.name}}
</option>
</select>
这篇关于角度:ng-select不显示ng-selected值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!