Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use reactive form with angular 2 dropdown multiselect

I'm trying to use the angular 2 dropdown multiselect library with reactive forms.

I have followed the tutorial for reactive model and have this:

this.myOptions = [
    { id: 1, name: 'English' },
    { id: 2, name: 'French' },
];

this.form = this.formBuilder.group({
    langs:[1, 2]
});

And in my html (in pug):

ss-multiselect-dropdown([options]='myOptions', formControlName='langs')

And get the following error: TypeError: this.validator is not a function

So I've tried:

this.form = this.formBuilder.group({
    langs:this.formBuilder.array([1, 2])
});

And get the following error: TypeError: control.registerOnChange is not a function

What am I doing wrong? Is this a bug?

You can see a plunker here

like image 846
ncohen Avatar asked Feb 14 '26 04:02

ncohen


1 Answers

As I understand from your Question that, You want to select both values on init.

this.myForm = this.formBuilder.group({
  optionsModel: [[1,2]] // Default model
});

Both values will be selected default

Updated Plunker : https://plnkr.co/edit/tvLYUzgsCkXODXX6qKrN?p=preview

like image 192
Yatin patel Avatar answered Feb 16 '26 17:02

Yatin patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!