在具有多个选择组件的“选择”中设置默认选择的项目

时间:2018-10-10 09:25:00

标签: angular angular-material

我正在使用选择多项选择组件。

enter image description here

我想像这样默认选择2个项目。

enter image description here

我冲浪了,但是我只获得了基本选择组件的资源,我该如何实现?

1 个答案:

答案 0 :(得分:1)

我已经在这里完成了,请检查https://stackblitz.com/edit/angular-zs2wa5?file=app/select-multiple-example.ts

export class SelectMultipleExample {
  toppings;
  toppingList: string[];

  constructor() {
    this.toppings = new FormControl();
    this.toppingList= ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
    this.toppings.value = ['Mushroom', 'Onion', ];
    console.log(this.toppings);
  }
}
相关问题