gpt4 book ai didi

angular - 组件 'mat-table' 和指令 '' 之间有什么区别?
转载 作者:行者123 更新时间:2023-12-02 18:57:23 24 4
gpt4 key购买 nike

<mat-table>
<table mat-table ...>

我发现了类似的问题Should I use "<table mat table ... " or "<mat-table ..." ,但我还是有一个误区。Angular Material 网站 https://material.angular.io/components/table/overview#tables-with-code-display-flex-code-有一个小注释:

Note that this approach means you cannot include certain native-table >features such colspan/rowspan or have columns that resize themselves based on >their content.

但我不明白什么:

or have columns that resize themselves based on their content means.

您能否举个例子,哪些列正在调整大小?

最终,我想实现表格在移动设备上的正确显示(使用mat-table组件这更容易做到,因为他使用了Flex),这里是一个例子https://stackblitz.com/edit/angular-mohmt5?file=app%2Ftable-basic-example.ts我想立即了解上面的注释可能会遇到哪些困难。

最佳答案

来自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一起使用

关于angular - 组件 'mat-table' 和指令 '<table mat-table>' 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58210966/

24 4 0