вот рабочий пример
рабочий пример
.html
<form [formGroup]="formGroup">
<mat-form-field>
<mat-label>Toppings</mat-label>
<mat-select formControlName="toppings" multiple (selectionChange)=" showSelectValue($event.value)">
<mat-option *ngFor="let topping of toppingList" [value]="topping.name"
>{{topping.name}}</mat-option>
</mat-select>
</mat-form-field>
<p>You selected: {{selected}}</p>
</form>
.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, Validators } from '@angular/forms';
/** @title Select with multiple selection */
@Component({
selector: 'select-multiple-example',
templateUrl: 'select-multiple-example.html',
styleUrls: ['select-multiple-example.css'],
})
export class SelectMultipleExample implements OnInit {
selected: any[];
constructor(private formBuilder: FormBuilder) { }
formGroup = this.formBuilder.group({ 'toppings': [null, Validators.required] });
toppingList: any[] = [
{ id: 1, name: 'Extra cheese' },
{ id: 2, name: 'Mushroom' },
{ id: 3, name: 'Onion' },
{ id: 4, name: 'Pepperoni' },
{ id: 5, name: 'Sausage' },
{ id: 6, name: 'Tomato' }
];
ngOnInit() {
this.formGroup.controls.toppings.setValue(this.selected);
}
showSelectValue(mySelect)
{
this.selected=mySelect;
console.log(mySelect);
}
}
/** Copyright 2019 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license */