我正在使用 angular5mat-selection-list
在同一组件中创建多个。
列表选择-example.html
Shoes:
<mat-selection-list #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes"
[value]="shoe">
{{shoe}}
</mat-list-option>
</mat-selection-list>
<button mat-button (click)="deselectShoes()">Deselect all Shoes</button>
Cloths:
<mat-selection-list #cloths>
<mat-list-option *ngFor="let cloth of typesOfCloths"
[value]="cloth">
{{cloth}}
</mat-list-option>
</mat-selection-list>
<button mat-button (click)="deselectCloth()">Deselect all Cloths</button>
列表选择example.ts
export class ListSelectionExample {
typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
typesOfCloths = ['Amaxa', 'Cotton', 'Woolen', 'Nylon'];
@ViewChild(MatSelectionList) shoes: MatSelectionList;
@ViewChild(MatSelectionList) cloths: MatSelectionList;
deselectShoes(){
this.shoes.deselectAll();
}
deselectCloth(){
this.cloths.deselectAll();
}
ngOnInit(){
}
}
这是完整的代码:https ://stackblitz.com/edit/angular-i3pfu2-dla3rd?file=app%2Flist-selection-example.ts
在此示例中,deselectShoes()
方法按预期工作。但deselectCloth()
没有按预期工作,仅取消选择鞋子 。
我们如何解决这个问题?