无法在angularjs下拉菜单中设置选定的值 [英] Unable to set selected value in angularjs dropdown

查看:80
本文介绍了无法在angularjs下拉菜单中设置选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用html下拉列表,并绑定了angularjs函数的值,如下所示的值

I am using html dropdown and binded the values from angularjs funtion, the values like below

function getStates() {
return [
    {
        "name": "Alabama",
        "abbreviation": "AL"
    },
    {
        "name": "Alaska",
        "abbreviation": "AK"
    }];
}

我的下拉列表是

<select class="form-control" 
        ng-model="user.state" name="state"
        ng-options="item.name for item in  states track by item.abbreviation">
   <option value="">-- choose State --</option>
</select>

在我的作用域变量 user.state 中,我得到了一个缩写值,该值已由某些函数预先加载,基于该缩写值,下拉列表的选定值应显示在html页面中.

In my scope variable user.state i got an abbreviation value which is preloaded by some function, based on that abbreviation value the selected value of dropdown should be shown in the html page.

欢迎提出宝贵的意见...

valuable comments are welcome...

推荐答案

您需要正确的 ngOptions 语法 value作为集合中项目的文本

ng-options="item.abbreviation as item.name for item in states"

这篇关于无法在angularjs下拉菜单中设置选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆