To set default selected item in Select with multip

2019-06-14 01:48发布

This question already has an answer here:

I am using Select with multiple selection component.

enter image description here

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

enter image description here

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

1条回答
三岁会撩人
2楼-- · 2019-06-14 02:17

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);
  }
}
查看更多
登录 后发表回答