来自source如果您看到指令的选择器可以用作元素 mat-table
或表的属性 table[mat-table]
@Component({
...
selector: 'mat-table, table[mat-table]',
...
})
export class MatTable<T> extends CdkTable<T> {}
<小时/>
Option 1: mat-table
: When you use as an element it uses CSS flex-box properties to align your data/table so when you have very long text it will not resize automatically unless specified otherwise. Note using this option you have to compromise on rowspan
and colspan
such as if the need arises you can't span your rows/cols
Stackblitz:https://stackblitz.com/edit/angular-prq2ju
Option 2: table[mat-table]
: When you use as an attribute to html table the td takes care of auto resizing its content based on the cell in turn based to the column. So the whole column gets the width
Stackblitz:https://stackblitz.com/edit/angular-pxpwet
<小时/>
现代的方法是使用 Option-1 CSS flex-box 方法,但是如果单元格中的内容很长,您可以将列宽指定为一个很大的数字,但如果您不想去很多麻烦你可以将它与Option-2 native html table/tr/td一起使用
我是一名优秀的程序员,十分优秀!