gpt4 book ai didi

angular - 嵌入式模板上的任何指令均未使用属性绑定(bind) matHeaderRowDef

转载 作者:太空狗 更新时间:2023-10-29 17:42:45 25 4
gpt4 key购买 nike

这是表格 html:

<mat-table matSort class="inbox__messages" #table [dataSource]="dataSource">

<!-- Building Column -->
<ng-container matColumnDef="building">
<mat-header-cell *matHeaderCellDef>
<div class="inbox__messages__header">
<h3 class="inbox__messages__header-label">Bâtiments</h3>
<mat-form-field class="inbox__messages__dropdown">
<mat-select placeholder="Choisir un bâtiment">
<mat-option *ngFor="let building of buildings" [value]="building.value">
{{ building.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</mat-header-cell>
<mat-cell *matCellDef="let element">
<span class="inbox__messages__body-building">{{element.building}}</span>
</mat-cell>
</ng-container>

<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" matRipple class="element-row" [class.expanded]="expandedElement == row"
(click)="expandedElement = row"></mat-row>

这个错误发生在 ng 测试中。我错过了什么?我已将 MatHeaderRowDef 导入到我的组件和模块中。

最佳答案

关于属性 ma​​tHeaderRowDefma​​tRowDefColumns,我们遇到了完全相同的问题。我们通过简单地在单元测试 spec 文件中导入 Material 表模块, MatTableModule 来解决这个问题。

具体来说,我们将其导入到初始声明中,然后导入到 beforeEach block 中。

为了更好地说明,这里是 my-awesome.component.spec.ts 文件:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MyAwesomeComponent } from './my-awesome.component';
import { MatTableModule } from '@angular/material';

describe('MyAwesomeComponent', () => {
let component: MyAwesomeComponent;
let fixture: ComponentFixture<MyAwesomeComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MyAwesomeComponent ],
imports: [ MatTableModule ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MyAwesomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

希望这有帮助:)

关于angular - 嵌入式模板上的任何指令均未使用属性绑定(bind) matHeaderRowDef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51085422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com