Reputation: 597
I am using angular2-multiselect-dropdown
for multiple dropdown in angular4. It's working perfect while creating the records, but not working fine during updation.
All previously selected values should be checked, and not able to select twice. but here it's not already selected and one can select same value again.
attaching screenshot, please let me know what can i do. will update my code if required.
Thanks in advance.
Upvotes: 1
Views: 5173
Reputation: 554
You can use patchValue()
method under FormBuilder to set single control in the form like
this.formGroup.patchValue({
control-name:value
})
this.form.controls['control-name'].patchValue(value)
NOTE: Works with specific control only
Upvotes: 0
Reputation: 554
If you are using angular forms, like formgroup, then you can use setValue()
method to set the value.
Please refer angualr forms.
Example:
this.form-name.setValue({
dropdown : some-value
})
Upvotes: 1
Reputation: 597
I got the solution, Posting here as answer so that no one finds the same issue. It was a tiny change that makes me crazy for hours. Here is the solution, the main difference was id for edit is string and for create is integer. After making it similar problem is resolved. Angular2-multiselct is really awesome.
DataList on Edit:
[{id: "1", itemName: "Text1", value: "1"},
{id: "2", itemName: "Text2", value: "2"},
{id: "3", itemName: "Text3", value: "3"}]
DataList on Create:
[{id:1, itemName: "Text1", value: "1"},
{id:2, itemName: "Text2", value: "2"},
{id:3, itemName: "Text3", value: "3"},
{id:4, itemName: "Text4", value: "4"},
{id:5, itemName: "Text5", value: "5"}]
Upvotes: 1