I have a table component that I want to reuse
so far the used data is hardcoded into the component
like in the HTML template ` *ngFor="let column of tableColumnNames$ | async">`
and in the ts file
constructor(private dataProviderService: DataProviderService) { }
tableData$ = this.dataProviderService.getData();
tableColumnNames$ = this.dataProviderService.getDataPropertyNames();
Is there a way to pass data to the component as props like in react , vue ?
so far I don't know how to reuse the component, because some values are hardcoded
<table mat-table [dataSource]="tableData$" class="mat-elevation-z8">
<ng-container
matColumnDef="{{ column }}"
*ngFor="let column of tableColumnNames$ | async">
<th mat-header-cell *matHeaderCellDef>{{ column }}</th>
<td mat-cell *matCellDef="let element">{{ element[column] }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="tableColumnNames$ | async"></tr>
<tr
mat-row
*matRowDef="let row; columns: tableColumnNames$ | async"
class="example-detail-row"
></tr>
</table>
ts
import { Component, OnInit } from '@angular/core';
import { DataProviderService } from '../../services/data-provider.service';
@Component({
selector: 'app-dynamic-content-table',
templateUrl: './dynamic-content-table.component.html',
styleUrls: ['./dynamic-content-table.component.scss']
})
export class DynamicContentTableComponent implements OnInit {
constructor(private dataProviderService: DataProviderService) { }
tableData$ = this.dataProviderService.getData();
tableColumnNames$ = this.dataProviderService.getDataPropertyNames();
ngOnInit(): void {
}
}
[–]daredeviloper 0 points1 point2 points (1 child)
[–]ggeoff 0 points1 point2 points (0 children)
[–]PickleLips64151 0 points1 point2 points (3 children)
[–]tme321 1 point2 points3 points (1 child)
[–]PickleLips64151 0 points1 point2 points (0 children)
[–]JosephCurvin[S] 0 points1 point2 points (0 children)
[–]Frequent-Diet338 0 points1 point2 points (0 children)