Select - 预填 select 倍数

Ng Select - Prefill select multiple

我正在尝试预填充 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>

问题:select 组件不显示 selected 选项。在这种情况下,作为 tipo==1,selected 标签应该是 'Equipo' 但没有显示。

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

尝试使用它来获取数据:

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

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

试试这个。

this.tipo = ["1"];