如何在角度6的下拉菜单中设置双向绑定数据? [英] How to set two way binding data in dropdown in angular 6?
问题描述
我有这样的数据.
[
{
"user_id": 1,
"name": "John"
},
{
"user_id": 2,
"name": "Doe"
},
...
]
在应用程序中,我设置了两个下拉菜单,分别仅显示user_id和name.
In app, I have set two dropdown for show only user_id and name respectively.
对于用户ID,我使用了简单的select
和option
.
For user id I have used simple select
and option
.
对于name
,我使用了ngx-select-dropdown
.
现在我必须进行两种方式的绑定,当我选择Doe
时,id下拉列表2
将自动绑定.以同样的方式,如果我选择ID 1
,则John
将自动选择.
Now I have to make two way binding, when I select Doe
then id dropdown 2
will automatically bind. Same way if I choose id 1
then John
will autimatically select.
我的设计如下.
推荐答案
我已经通过reactive form group
解决了我的问题.它很容易为我提供价值,并且已经借助patchValue()
功能设置了它的形式价值.而且对我来说很好.
I have solved my issue with the help of reactive form group
. It provides me value easily and I have set it's form value with the help of patchValue()
feature. And it works fine for me.
这篇关于如何在角度6的下拉菜单中设置双向绑定数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!