【问题标题】:Ng Select - Prefill select multipleNg Select - 预填充选择多个
【发布时间】:2019-11-12 11:11:24
【问题描述】:

我正在尝试预填 select multiple in angular

TS

  tipo:any;

  typeSelect: any = [
    { id: "1", descripcion: "Equipo" },
    { id: "2", descripcion: "Contadores" },
    { id: "3", descripcion: "Sensores" }
  ];

    this.tipo = 1;

HTML

  <ng-select [items]="typeSelect" name="tipo" bindLabel="descripcion" bindValue="id" placeholder="Tipo"
                [(ngModel)]="tipo" [multiple]="true" >
              </ng-select>

问题:选择组件不显示选定的选项。在这种情况下,由于 Tipo==1,选择的标签应该是 'Equipo' 但不显示。

那么知道为什么我可以解决这个问题并显示标签吗?

【问题讨论】:

    标签: angular jquery-select2


    【解决方案1】:

    您正在使用多选下拉菜单,因此ngModel 将包含一个数组。另外,您的id 是字符串而不是数字。

    试试这个。

    this.tipo = ["1"];
    

    【讨论】:

      【解决方案2】:

      尝试使用它来获取数据:

      <ng-select2 [data]="exampleData"></ng-select2> 
      

      【讨论】:

        猜你喜欢
        • 2016-03-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-12
        • 1970-01-01
        相关资源
        最近更新 更多