如何将数组绑定到多个选择下拉角2?

时间:2017-07-19 09:56:11

标签: angular

我正在使用Angular 2,想要将Employee的角色绑定到multiselct的下拉列表。我已经在从数据库中获取的下拉列表中有角色。 如果我单击编辑员工按钮,我想将角色绑定到该下拉列表并显示选择了哪些角色。怎么做?

html中的DropDown

<div class="form-group">
          <label>Employee Roles</label>
               <select id="dates-field2"  #role="ngModel" 
               style="height:200px;" name="Role" 
               class="multiselect-ui form-control" multiple="multiple" 
               [(ngModel)]="selectedRole" required >
              <option value="0">--Select--</option>
              <option *ngFor="let role of roles" value={{role.OID}}>
                    {{role.RollName}}
               </option>
         </select>
      </div>

角色模块

export class Role {
        OID: number;
        RollName: string;
        constructor(OID: number, RollName: string) {
              this.OID = OID;
              this.RollName = RollName;
       }
   }

.ts文件

observableRole: Observable<Role[]>
roles: Role[];
OnEditingStart(value: any) { 
       //here I want to set values to dropdown.
       this.OID = value.data.OID;
       this.observableRole = this.employeeService.getEmployeeRole(this.OID);
       this.observableRole.subscribe(
       roles =>  this.roles = roles,
       error => this.errorMessage = <any>error);
       console.log(this.role);
 }

0 个答案:

没有答案