我应该如何使用 Angular-2 中下拉列表中的多个 select 选项绑定数组

How should i bind array with multi select options from dropdown in Angular-2

我正在尝试将数组对象与多个 select 下拉列表绑定,这样我就可以将 selected 值传递给模型以与其他模型详细信息一起保存。

我在这里使用更改事件来接收选择的选项值,但该功能不起作用这里是我的代码:

HTML代码:

label class="col-md-3 form-control-label text-right">Customer Name</label>
           <div class="col-md-7">
             <select  multiple="multiple" class="js-example-basic-multiple form-control selectsizing" (change)="oncustomerSelect($event.target.value)" name="customer_name" [(ngModel)]="customer_name.customer" #customer_name="ngModel" [ngClass]="{ 'is-invalid': f.submitted && customer_name.invalid }"  required>
              <option></option>
              <option [value]="customernames.Business_name" *ngFor="let customernames of model_customername">{{customernames.Business_name}}</option>
     </select>

            </div>

在 select 下拉菜单的任何值上,应调用函数 oncustomerSelect(),这在 component.ts 中有描述,但无法完成此函数调用。

这是我的Component.ts:

 customer_name:any={
    customer:[]
};    
model:any={
product_type:"in stock",    
item_code:"ASD34", 
customer_name:[]=[]
} 

oncustomerSelect(value){
console.log("customer select::"+JSON.stringify(value));
var i=0;
this.model.customer_name[i]=value; 
i++; 
console.log("model customer::"+JSON.stringify(this.model.customer_name));  
}

请帮助我,如何在多个 select 中调用该函数以及我应该如何将数组与 selected 值绑定?

谢谢!

查看参考!在给定的 link 中,您可以看到您将获得下拉 selected 值,您可以添加 multi select 属性 并完成此操作

angular5-select-option-dropdown