【发布时间】:2016-02-22 21:58:08
【问题描述】:
我的资源对象中有一个方法:
resources.type
otherstuff: 'more strings'
type:'specifictype'
morestuff: 'morestuff'
用户可以使用下拉列表/通过另一个调用更改此类型,该调用获取所有可能类型的列表,该列表看起来像 resourceList.types,其中包含类似 json 的对象列表
types:
[
{name:'resourcetype1'},
{name:'resourcetype2'},
etc...
],
我的 html 看起来像:
<select ng-model="resources.type" ng-options="name.name for name in resourceList.types">
</select>
选择/下拉框填充了我的 resourceList.type 内容,但是当页面加载时,ng-model 未设置为已选择的资源类型。当您单击时,它实际上会在下拉列表顶部选择一个空白条目。角度挑剔吗?如何让 ng-model 以我想要的方式运行?
我尝试使用 ng-options 以不同的方式获得重复,但我觉得这更像是角度连接模型的方式。它只是将字符串与 ng-options 列表匹配吗?
这是 plnkr,你可以看到它没有默认为 type1
【问题讨论】:
-
很抱歉,我无法理解您的架构以及问题所在。你能提供一个 Plunker 来演示这个问题吗?
-
简单地说,我希望无论 ng-model 是什么,都将下拉菜单默认设置为 ng-options 中 resourceList.types 中的任何字符串。这有意义吗?
标签: angularjs ng-options