I have 2 Angular Modules:
- Student
- Course
Inside Course I have a Component (CourseListComponent) that I would like to show nested inside a Student component (StudentDetailsComponent). So I need to export that component from Course module:
@NgModule({
declares [ CourseListComponent ],
exports: [ CourseListComponent ]
})
Also I need to import Course module inside Student:
@NgModule({
declares: [ StudentListComponent, StudentDetailsComponent ],
imports: [ CourseModule ]
})
Inside of the StudentListComponent I have a MatTable with MatTableDataSource that has some data:
this.students = this.route.snapshot.data.students;
this.dataSource = new MatTableDataSource(this.students);
When i switch to StudentDetailsComponent I would like to show the list of the courses the student is enrolled in. I would also like to do that inside a MatTable:
this.courses = this.route.snapshot.data.courses; // returns correct courses
this.dataSource = new MatTableDataSource(this.courses); // changes filteredData
But when the page loads it shows just the empty table. I get no error in the console, just an empty table.
Does anyone have an idea how to fix this problem?
Thank you!
Here is the HTML:
<table mat-table [dataSource]="dataSource" matSort class="mat-elevation-z8" matSort>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header class="aligned-columns">
{{ 'COURSE-LIST.ID' | translate }}
</th>
<td mat-cell *matCellDef="let course">
{{course.id}}
</td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>
{{ 'COURSE-LIST.NAME' | translate }}
</th>
<td mat-cell *matCellDef="let course">
{{ course.name}}
</td>
</ng-container>
<ng-container matColumnDef="year">
<th mat-header-cell *matHeaderCellDef mat-sort-header>
{{ 'COURSE-LIST.YEAR' | translate }}
</th>
<td mat-cell *matCellDef="let course">
{{ course.year}}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
</table>
In CourseListComponent:
displayedColumns: string[] = ['id', 'name', 'year'];
courses: ICourse[];
And the model:
export inteface ICourse {
id: number;
name: string;
year: string;
}