我有一个Angular 13
应用程序&;构建了一个名为app-table
的通用可重用组件
HTML
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>DOB</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of tableItems">
<td> {{ item.name }}</td>
<td> {{ item.email } </td>
<td> {{ item.dob }} </td>
</tr>
</tbody>
</table>
Coment.ts coment.ts
import { Component, Input, OnInit} from '@angular/core';
import { TableItem } from './model/tableItem';
@Component({
selector: 'app-table',
templateUrl: './table.component.HTML',
styleUrls: ['./table.component.css'],
})
export class TableComponent implements OnInit {
@Input() tableItems: TableItem[] = [];
constructor() {}
ngOnInit(): void {}
}
目前,该组件可以跨4-5个位置重用,但是该组件的可重用性仅限于name
、email
、dob
个字段.我想让它变得通用,这样任何型号都可以链接到这个组件,并且可以在整个应用程序中重复使用.
请提个建议.谢谢!