angular - 不能在属性选择器中使用 mat-tab

我尝试将这两个选项卡放入两个单独的组件中,如下所示:

<mat-tab-group animationDuration="0ms">
    <mat-tab app-tab [label]="'blabla1'" [data]="aaaData"></mat-tab>
    <mat-tab app-tab [label]="'blabla2'" [data]="bbbData"></mat-tab>
</mat-tab-group>

...

@Component({
    selector: 'mat-tab[app-tab]',
    templateUrl: './tab.component.html',
    styleUrls: ['./tab.component.scss']
})
export class TabComponent {
    @Input() label: string;
    @Input() data: any;

在 module.ts 中:

import {MatTabsModule} from '@angular/material';
@NgModule({
    imports: [
        MatTabsModule,

我得到了错误:

Uncaught Error: Template parse errors: More than one component matched on this element. Make sure that only one component's selector can match a given element. Conflicting components: MatTab,TabComponent ("

或者,如果我使用 a mat-tab-link 而不是 mat-tab,并且 a[mat-tab-link][app-tab ] 而不是 mat-tab[app-tab],我会得到

Uncaught Error: Template parse errors: Can't bind to 'data' since it isn't a known property of 'a'. ("mat-tab-group animationDuration="0ms">

而且它也不支持 label 属性:

Uncaught Error: Template parse errors: Can't bind to 'label' since it isn't a known property of 'a'. ("s="tabs-wrap">][label]="'blabla1'" [data]="aaaData">

最佳答案

我会在 mat-tab 中放置另一个元素,以避免混淆 Material 的组件选择器。

更像是:

<mat-tab-group animationDuration="0ms">
    <mat-tab label="blabla1">
        <tab-component [data]="aaaData"></tab-component>
    </mat-tab>
    <mat-tab label="blabla2">
        <tab-component [data]="bbbData"></tab-component>
    </mat-tab>
</mat-tab-group>
@Component({
    selector: 'tab-component',
    templateUrl: './tab.component.html',
    styleUrls: ['./tab.component.scss']
})
export class TabComponent {
    @Input() data: any;

https://stackoverflow.com/questions/61087440/

相关文章:

javascript - 调整大小并使 PotlyJS 的 fiddle 图表响应

python - 使用 MCP3002 模数转换器控制 LED 亮度

javascript - react 导航和状态栏颜色在 View 更改时闪烁

node.js - 如何在 heroku 上部署 Node Media Server 应用程序

javascript - 本地加载keras模型到tensorflow.js

python - 使用 PyTorch 分布式 NCCL 连接失败

sql - 如何消除 DB2400 或任何 SQL 中 JSON_ARRAYAGG 中的重复行?

react-native - react native 文本输入键盘如何显示点而不是逗号?

Gitlab - 创建分支后运行脚本

amazon-web-services - 错误 1045 (28000) : Access den