要从动态大小的表的数据源中设置mat-select的选定值,您可以使用以下步骤和代码示例:
import { Component } from '@angular/core';
@Component({
selector: 'app-table',
template: `
{{row.name}}
{{option}}
`
})
export class TableComponent {
data = [
{ name: 'Row 1', selectedValue: 'Option 1' },
{ name: 'Row 2', selectedValue: 'Option 2' },
{ name: 'Row 3', selectedValue: 'Option 3' }
// Add more rows as needed
];
options = ['Option 1', 'Option 2', 'Option 3'];
onSelectionChange(row: any, value: any) {
row.selectedValue = value;
}
}
import { Component } from '@angular/core';
@Component({
selector: 'app-parent',
template: `
`
})
export class ParentComponent { }
通过上述示例,您将能够创建一个包含动态大小表的组件,并能够在mat-select中设置并保存选定值。