so the thing is that a MatSelect with multiple enabled,
takes an Array of value,
If you want to toggleAllNode by clicking on one,
you have to call a function that will set all the value inside the MatSelect,
it is why you need another variable
so here is your template
<mat-form-field appearance="fill">
<mat-select [value]='value' class="user-control" multiple>
<mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
<mat-option [value]="store.id" *ngFor="let store of stores"
(click)="valueChange(store.id)" >{{ store.name }}</mat-option>
</mat-select>
And the .ts
export class AppComponent {
value = [];
selectAll = false;
stores = [
{ id: 2, name: "store - 1" },
{ id: 3, name: "store - 2" },
{ id: 4, name: "store - 3" },
{ id: 5, name: "Store - 4" }
];
constructor(private fb: FormBuilder) {}
ngOnInit() {}
// Function used to properly bind the values on 1 MatOption
valueChange(id: number) {
if (this.value.indexOf(id) > -1) {
//find the index of the element to delete if present
const pos = this.value.indexOf(id);
this.value.splice(pos, 1);
} else {
// else you push the selected value
this.value.push(id);
}
}
//function to select of deselect All
toggleAllSelection() {
this.selectAll = !this.selectAll;
console.log(this.selectAll);
if (this.selectAll == true) {
this.value = [0, 2, 3, 4, 5];
} else {
this.value = [];
}
}
}
(Edit after missing function for single value).
Since you don't use any form from angular at all,
you need to handle all actions by hand to make the value communicate properly between MatSelect and the graphic Output.
Here value is use to keep the result of the selected Node,
But also by passing it in the template of the mat-form-field,
it allows the MatSelect to check correctly the corresponding MatOptions
A link to the updated stack blitz :
https://stackblitz.com/edit/angular-material-with-angular-v5-3arsoh?file=app/app.component.html
Still i think you could have less code just with a formControl if you don't want to use a FormGroup or a FormBuilder.