To set default selected item in Select with multiple selection component [duplicate]

六眼飞鱼酱① 提交于 2019-12-23 04:57:23

问题


I am using Select with multiple selection component.

I want to make 2 items to be selected by default like this.

I have surfed,but i got resources only for Basic select component, How can i achieve this?


回答1:


I have done it here please check 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);
  }
}


来源:https://stackoverflow.com/questions/52736875/to-set-default-selected-item-in-select-with-multiple-selection-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!