AngularJS:ng-selected 不显示选定的值 [英] AngularJS: ng-selected doesn't show selected value
问题描述
在标题上,我的选择似乎无法显示所选值,例如,正确选择...
As on the title my select doesn't seem able to show the selected value, that is for instance, correctly selected...
<md-input-container flex>
<label>Anno selezione</label>
<md-select name="annoSelect" ng-model="vm.anno_attuale"
ng-value="vm.progetto.pprs[$index].anno"
ng-selected="item.selected" >
<md-option ng-repeat="item in vm.progetto.pprs" >
{{vm.progetto.pprs[$index].anno}}
</md-option>
</md-select>
</md-input-container>
我尝试了一些在堆栈上找到的解决方案,例如:Angular:ng-select 不显示 ng-selected 值一个>
I tried with some solutions found on stack, such as that one: Angular : ng-select does not show ng-selected value
但他们中的任何一个都没有解决问题......有什么想法吗?
but any of them didn't fix the issue... Any idea?
推荐答案
来自文档:
注意:ngSelected
不与 select
和 ngModel
指令交互,它只设置 selected
属性在元素上.如果您在选择上使用 ngModel
,则不应在选项上使用 ngSelected
,因为 ngModel
将设置选择值和选择的选项.
Note:
ngSelected
does not interact with theselect
andngModel
directives, it only sets theselected
attribute on the element. If you are usingngModel
on the select, you should not usengSelected
on the options, asngModel
will set the select value and selected options.
—AngularJS ng-selected Directive API 参考
ng-value
指令位置错误:
<md-input-container flex>
<label>Anno selezione</label>
<md-select name="annoSelect" ng-model="vm.anno_attuale"
̶n̶g̶-̶v̶a̶l̶u̶e̶=̶"̶v̶m̶.̶p̶r̶o̶g̶e̶t̶t̶o̶.̶p̶p̶r̶s̶[̶$̶i̶n̶d̶e̶x̶]̶.̶a̶n̶n̶o̶"̶
̶n̶g̶-̶s̶e̶l̶e̶c̶t̶e̶d̶=̶"̶i̶t̶e̶m̶.̶s̶e̶l̶e̶c̶t̶e̶d̶"̶ ̶ >
<md-option ng-repeat="item in vm.progetto.pprs"
ng-value="item.anno">
̶{̶{̶v̶m̶.̶p̶r̶o̶g̶e̶t̶t̶o̶.̶p̶p̶r̶s̶[̶$̶i̶n̶d̶e̶x̶]̶.̶a̶n̶n̶o̶}̶}̶
{{item.anno}}
</md-option>
</md-select>
</md-input-container>
有关更多信息,请参阅使用 ngValue
将模型绑定到对象数组
For more information, see Using ngValue
to bind the model to an array of objects
这篇关于AngularJS:ng-selected 不显示选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!