0

I am using jquery into angular to multiple select value from dropdown but the problem is when I select and try to console the function add "1" as a first number before the selected array

This is the HTML page:

<select  class="ui fluid multiple selection dropdown" id="multi-select">
    <option *ngFor="let objectif of listObjectif" [value]="objectif.id_obj">{{objectif.des_obj}}
    </option>
</select>

This is my code into the controller:

this.selectedObjectif = <[any]>[];
this.selectedObjectif = $('select#multi-select').dropdown('get value');

When I try to call the function, this is what I get:

(2) ["1", Array(4)]
0:"1"
1:(4) ["1", "8", "3", "16"]
length:2

The problem is I don't want to get the first value "1", I just want to get the array directly.

0

1 Answer 1

1

you can use ngModel and modelChange to get the selected value or object.

export class mySelectClass {

selectedObjectif: any;

mySelectedValue() {
 console.log(selectedObjectif);
}
<select [(ngModel)]="selectedObjectif" (ngModelChange)="mySelectedValue()">
  <option *ngFor="let objectif of listObjectif" 
   [ngValue]="objectif.id_obj">{{objectif.name}}
  </option>
</select>

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

3 Comments

when i use ngModel i won't be able to see the first element of the list that's why i worked with jquery
what do you mean by that please elaborate or update code of what you tried and also which jquery plugin are you using ?
what i am trying to say is : when i see the dropdown i don't see the first item of the dropdown and once i start the scroll the items start show up , and that's why i ve used jquery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.