【问题标题】:multiselection dropdown angular 4多选下拉角4
【发布时间】:2017-11-18 12:39:27
【问题描述】:

我想要一个带有用户名的下拉列表,然后我可以检查多个用户并将所选用户的 ID 保存在数组中以循环它们.. 我使用 angular-2-dropdown-multiselect 但我无法更改其中的价值观 [https://www.npmjs.com/package/angular-2-multiple-selection]

<select  class="custom-select" [(ngModel)]="username" formControlName="username" multipe >
     <option *ngFor="let user of users" [value]="user.user_ID"> {{ user.user_Name }} </option>
</select>

我想让 myOptions 来自 API 的同等响应

我试图在包工作的时候做出这个响应:

this.dataStorageService.getUsers().subscribe(response => {
      this.users= response.json() ;
    });
    for(let i = 0 ; i < this.users.length; i++){
        this.test= this.users[i].user_Name;
        this.testId = this.users[i].user_ID;
        this.myOptions=[
            { id : this.testId , name: 'this.test'}
            ]
    }

但它不起作用....

【问题讨论】:

标签: angular api typescript multi-select


【解决方案1】:

由于您想使用带有复选框的下拉菜单,因此普通选择不带有复选框,您应该使用一些库,例如primeng 或 angular material 或制作您自己的组件。

使用 Angular 材质。只需将多个或 [multiple]="true" 添加到您的 mat-select 中即可。

DEMO

【讨论】:

    猜你喜欢
    • 2018-08-04
    • 2018-09-25
    • 1970-01-01
    • 2016-12-30
    • 2018-11-26
    • 2019-08-03
    • 2018-09-23
    • 2019-03-15
    • 2018-04-13
    相关资源
    最近更新 更多