There are several methods to verify the following:
within component.html
<mat-form-field>
<mat-select placeholder="Toppings" (selectionChange)="onChange($event.value)" multiple>
<mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
</mat-select>
</mat-form-field>
and in component.ts
toppingList: string[] = ['Extra cheese', 'Mushroom', 'Onion', 'Pepperoni', 'Sausage', 'Tomato'];
selectedList: any = []; // store selected options here
onChange(event) {
let missing = null;
for (let i = 0; i < this.selectedList.length; i++) {
if (event.indexOf(this.selectedList[i]) == -1) missing = this.selectedList[i]; // Current[i] isn't in prev
}
if (missing)
alert(missing);
this.selectedList = event;
}
For a live demonstration, you can visit this Stackblitz link