gpt4 book ai didi

angular - 无法绑定(bind)到 'character',因为它不是 'tr' 的已知属性

转载 作者:行者123 更新时间:2023-12-02 11:14:46 33 4
gpt4 key购买 nike

导入,变量声明完成。仍然抛出错误。另请阅读 SO 上的旧问题。

app.module.ts:

import { HotelTableComponent } from './hotel-table/hotel-table.component';
import { HotelTableRowComponent } from './hotel-table-row/hotel-table-row.component';

@NgModule({
declarations: [
AppComponent,
HotelTableComponent,
HotelTableRowComponent
],

hotel-table-row.component.ts:

@Component({
selector: 'app-hotel-table-row',
.....

export class HotelTableRowComponent implements OnInit {

@Input() character: any;
@Input() columns: string[];

hotel-table.component.html:

  <table>
<tr>
<th *ngFor="let c of columns">{{c}}</th>
</tr>

<tr *ngFor="let ch of characters | async"
app-hotel-table-row
[character]="ch"
[columns]="columns">
</tr>

</table>

控制台:

compiler.js:215 Uncaught Error: Template parse errors:
Can't bind to 'character' since it isn't a known property of 'tr'. ("
<tr *ngFor="let ch of characters | async"
app-hotel-table-row
[ERROR ->][character]="ch"
[columns]="columns">
</tr>
"): ng:///AppModule/HotelTableComponent.html@7:4
Can't bind to 'columns' since it isn't a known property of 'tr'. ("
app-hotel-table-row
[character]="ch"
[ERROR ->][columns]="columns">
</tr>

"): ng:///AppModule/HotelTableComponent.html@8:4

最佳答案

为了将组件绑定(bind)到属性,您需要将组件名称放在方括号中,因为组件选择器是实际的 CSS 选择器,并且在 CSS 中按名称选择属性,您必须将其放在方括号中。试试这个

selector: '[app-hotel-table-row]'

查看this发帖了解更多详情。

关于angular - 无法绑定(bind)到 'character',因为它不是 'tr' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50655356/

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