【问题标题】:Bind input and select to one ng-model绑定输入并选择一个 ng-model
【发布时间】:2014-11-12 10:24:37
【问题描述】:

绑定模型同时输入和选择有问题。当从下拉列表中选择模型时,输入值会发生变化。但如果输入的输入值等于列表的某些值,则下拉菜单不会改变。

Example on Plunker

<select 
  ng-model="Choice.SelectedOption"                 
  ng-options="choice.ID as choice.Name for choice in Choice.Options">
</select>

{{Choice.SelectedOption.ID}}
input model <input type="text" ng-model="Choice.SelectedOption">
input value {{ Choice.SelectedOption }}

从下拉列表中更改模型,然后尝试将模型从输入更改为 1,2 或 3(它是用户 ID)

【问题讨论】:

    标签: javascript angularjs angular-ngmodel


    【解决方案1】:

    &lt;input type="text"&gt; 更改为&lt;input type="number"&gt; 修复了它。

    http://plnkr.co/edit/FQqVGZz51SCJunWPZwfd?p=preview

    【讨论】:

    • 或将 ID 更改为 String 类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2015-05-06
    • 2015-03-08
    • 2016-04-26
    • 1970-01-01
    • 2021-01-19
    相关资源
    最近更新 更多