2

I've finally managed to load the softsimon angular-2-multiselect-dropdown. How do i get the selected options ?

I'm using softsimon angular-2-multiselect-dropdown v 0.4.0

**Edit: **

<ss-multiselect-dropdown [options]="ArrayObject" [texts]="myTexts" [settings]="mySettings" (onModelChange)="dummy"></ss-multiselect-dropdown>

ArrayObject is :

    for(let x = 0; x < this.productArray.length ; x++ ){
        let temp={id : x , name : this.productArray[x]};
        this.ArrayObject[x]=temp;
    }

Output asked :

[ { "id": 0, "name": "redBox" }, { "id": 1, "name": "orangeBox" } ]

Thanks in advance

3
  • 2
    Welcome to StackOverflow. Please post the code that demonstrates what you tried to accomplish, what you tried and where you failed. Commented Jan 17, 2017 at 7:30
  • Why are you not just using this.ArrayObject.push({id : x , name : this.productArray[x]});. What do you get if you add <div>{{ArrayObject | json}}</div> to your page? Can you please add this output to your question as well? Commented Jan 17, 2017 at 7:39
  • @GünterZöchbauer i'll make the changes you've suggested . i have added the output you asked . Commented Jan 17, 2017 at 7:44

1 Answer 1

4

You can add an ngModel to the ss-multiselect-dropdown like this:

<ss-multiselect-dropdown 
   [options]="ArrayObject" 
   [texts]="myTexts" 
   [settings]="mySettings" 
   (ngModelChange)="onChange($event)"
   [ngModel]="selectedTexts"
></ss-multiselect-dropdown>

You have to change your component which is using this multiselect to something like this:

export class TextSelectorComponent {

   public selectedTexts: any[] = [];

   public onChange(): void {
      console.log(this.selectedTexts);
   }

}

After a change is triggered, the ngModel will then contain the selected values inside the selectedTexts variable.

Sign up to request clarification or add additional context in comments.

5 Comments

I added [(ngModel)] to the html tag @PierreDuc, and i got an error as ngModel is not a nown property of ss-multiselect-dropdown. Further ,i removed [(ngModel)] and added a debugger point on line containing onChange() , the function is not executed .
Have you added the angular FormModule to your imports ? I've also updated my answer to only use the [] notation and not the [()]. You can try that as well. This is because there is already a ngModelChange listener
Now it is working . Thank you :) . I had not imported the FormsModule . I have aapplied the changes on ngModel .
Can I then ignore [options]="ArrayObject" in <ss-multiselect-dropdown ?
The first value of the selection is "". Anyone faced this?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.