I have two components. The first component contains Angular Material Table while the second one going to display the details of the row clicked in table.
The first component:
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>
Now the function getRecord() is working as intended.
getRecord(row: GoodsList){
console.log(row);
}
The data is captured inside row variable but now how can I pass it into another component based on what I clicked?
<router-outlet>?rowinto a service with a Subject. After that, you inject this service in both component.