How to add row component in table in Angular 7?(如何在 Angular 7 的表格中添加行组件?)
问题描述
我使用了最新版本的 angular.(7.2.0)我有个人 tr 组件,例如:
I use last version of angluar. (7.2.0) I have personal tr component like:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-table-row',
templateUrl: './table-row.component.html',
styleUrls: ['./table-row.component.scss']
})
export class TableRowComponent implements OnInit {
@Input() character: any;
@Input() columns: string[];
constructor() { }
ngOnInit() {
}
}
我想在表格中使用这个组件,例如:
I want to use this component inside table like:
<table class="mat-elevation-z8">
<tr>
   <th *ngFor="let c of columns">{{c}}</th>
</tr>
<tr app-table-row class="component-style table-row-component" *ngFor="let ch of characters | async" 
   [character]="ch" 
  [columns]="columns">
</tr>
</table>
得到如下错误:
Can't bind to 'character' since it isn't a known property of 'tr'. ("table-row class="component-style table-row-component" *ngFor="let ch of characters | async" 
       [ERROR ->][character]="ch" 
      [columns]="columns">
  </tr>
"): ng:///AppModule/TableComponent.html@7:7
如何在表格中正确添加我的组件?
How to add my component correctly inside table?
推荐答案
将组件选择器定义为带方括号的属性选择器:
Define the component selector as an attribute selector with square brackets:
@Component({
  selector: 'tr[app-table-row]',
  ...
})
以便可以将其设置为 tr 元素的属性:
so that it can be set as an attribute of the tr element:
<tr app-table-row ...>
                        这篇关于如何在 Angular 7 的表格中添加行组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Angular 7 的表格中添加行组件?
				
        
 
            
        - 400或500级别的HTTP响应 2022-01-01
 - 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 - Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
 - Fetch API 如何获取响应体? 2022-01-01
 - 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
 - Flexslider 箭头未正确显示 2022-01-01
 - 失败的 Canvas 360 jquery 插件 2022-01-01
 - addEventListener 在 IE 11 中不起作用 2022-01-01
 - CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
 - Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
 
						
						
						
						
						