У меня есть два компонента. Первый компонент содержит Angular Таблица материалов, в то время как второй будет отображать детали строки, щелкнувшей в таблице.
Первый компонент:
const ELEMENT_DATA: GoodsList[] = [
{initial: 'J', eta: '20-01-2020', src: 'IN'},
{initial: 'N', eta: '20-01-2020', src: 'ON''}
]
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="ordered">
<th mat-header-cell *matHeaderCellDef> Initial </th>
<td mat-cell *matCellDef="let element"> {{element.initial}} </td>
</ng-container>
<ng-container matColumnDef="eta">
<th mat-header-cell *matHeaderCellDef> ETA </th>
<td mat-cell *matCellDef="let element"> {{element.eta}} </td>
</ng-container>
<ng-container matColumnDef="srt">
<th mat-header-cell *matHeaderCellDef> SRC </th>
<td mat-cell *matCellDef="let element"> {{element.src}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" (click)="getRecord(row)"></tr>
</table>
Теперь функция getRecord () работает как задумано.
getRecord(row: GoodsList){
console.log(row);
}
Данные записываются в переменную строки, но теперь, как я могу передать их в другой компонент, основываясь на том, что я нажал?