Raf*_*ira 2 angular-material angular
我有以下 HTML 组件:
<mat-selection-list #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes">
{{shoe.title}}
</mat-list-option>
</mat-selection-list>
<pre>
Options selected: {{this.result | json}}
</pre>
Run Code Online (Sandbox Code Playgroud)
这是 ts 组件,它包含一个数组,其中包含发送到 HTML 组件的数据。
ngOnInit() {
this.typesOfShoes = [
{
id: 1,
title: 'Aaa',
checked: true,
},
{
id: 2,
title: 'Bbb',
checked: false,
},
{
id: 3,
title: 'Ccc',
checked: true,
},
{
id: 4,
title: 'Ddd',
checked: false,
},
];
}
Run Code Online (Sandbox Code Playgroud)
我在StackBlitz 中留下了该项目的链接

mat-list-option 有一个 selected 属性,您可以为其分配一个布尔值。
所以这样的事情应该有效。
<mat-selection-list #shoes>
<mat-list-option *ngFor="let shoe of typesOfShoes" [selected]="shoe.checked">
{{shoe.title}}
</mat-list-option>
</mat-selection-list>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3326 次 |
| 最近记录: |