Skip to content

Commit d12811e

Browse files
author
Your Name
committed
Angular Material In Depth
1 parent e1dbc8f commit d12811e

File tree

3 files changed

+55
-28
lines changed

3 files changed

+55
-28
lines changed

src/app/course/course.component.html

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
11
<div class="course">
22

3-
<h2>{{course?.description}}</h2>
3+
<h2>{{course?.description}}</h2>
44

5-
<img class="course-thumbnail" [src]="course?.iconUrl">
5+
<img class="course-thumbnail" [src]="course?.iconUrl">
66

7-
<div class="spinner-container" *ngIf="loading">
7+
<div class="spinner-container" *ngIf="loading">
88

9-
<mat-spinner></mat-spinner>
9+
<mat-spinner></mat-spinner>
1010

11-
</div>
11+
</div>
1212

13-
</div>
13+
<table mat-table class="lessons-table mat-elevation-z8"
14+
[dataSource]="lessons">
1415

15-
<table mat-table class="lessons-table mat-elevation-z8"
16-
[dataSource]="lessons">
16+
<ng-container matColumnDef="seqNo">
1717

18-
<ng-container matColumnDef="seqNo">
18+
<th mat-header-cell *matHeaderCellDef>#</th>
1919

20-
<th mat-header-cell *matHeaderCellDef>#</th>
20+
<td mat-cell *matCellDef="let lesson">{{lesson.seqNo}}</td>
2121

22-
<td mat-cell *matCellDef="let lesson">{{lesson.seqNo}}</td>
22+
</ng-container>
2323

24-
</ng-container>
24+
<ng-container matColumnDef="description">
2525

26-
<ng-container matColumnDef="description">
26+
<th mat-header-cell *matHeaderCellDef>Description</th>
2727

28-
<th mat-header-cell *matHeaderCellDef>Description</th>
28+
<td mat-cell *matCellDef="let lesson">{{lesson.description}}</td>
2929

30-
<td mat-cell *matCellDef="let lesson">{{lesson.description}}</td>
30+
</ng-container>
3131

32-
</ng-container>
32+
<ng-container matColumnDef="duration">
3333

34-
<ng-container matColumnDef="duration">
34+
<th mat-header-cell *matHeaderCellDef>Duration</th>
3535

36-
<th mat-header-cell *matHeaderCellDef>Duration</th>
36+
<td class="duration-cell" mat-cell *matCellDef="let lesson">{{lesson.duration}}</td>
3737

38-
<td class="duration-cell" mat-cell *matCellDef="let lesson">{{lesson.duration}}</td>
38+
</ng-container>
3939

40-
</ng-container>
40+
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
4141

42-
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
42+
<tr mat-row *matRowDef="let lesson;columns:displayedColumns"></tr>
4343

44-
<tr mat-row *matRowDef="let lesson;columns:displayedColumns"></tr>
4544

45+
</table>
4646

47-
</table>
47+
<mat-paginator class="mat-elevation-z8"
48+
[length]="course?.lessonsCount"
49+
[pageSize]="3"
50+
[pageSizeOptions]="[3, 5, 10]">
4851

52+
</mat-paginator>
4953

54+
</div>
5055

5156

5257

src/app/course/course.component.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
.course {
33
text-align: center;
4-
max-width: 390px;
4+
width: 390px;
55
margin: 0 auto;
66
}
77

@@ -35,7 +35,7 @@
3535
.lessons-table {
3636
min-height: 360px;
3737
margin-top: 10px;
38-
max-width: 400px;
38+
width: 400px;
3939
margin-left: auto;
4040
margin-right: auto;
4141
tr:hover {
@@ -44,13 +44,15 @@
4444
}
4545
}
4646

47+
mat-paginator {
48+
width: 400px;
49+
margin-bottom: 200px;
50+
}
4751

4852
.spinner-container mat-spinner {
4953
margin: 130px auto 0 auto;
5054
}
5155

52-
53-
5456
.mat-column-seqNo {
5557
width: 32px;
5658
border-right: 1px solid black;

src/app/course/course.component.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export class CourseComponent implements OnInit, AfterViewInit {
2323

2424
loading = false;
2525

26+
@ViewChild(MatPaginator)
27+
paginator: MatPaginator;
28+
2629
constructor(private route: ActivatedRoute,
2730
private coursesService: CoursesService) {
2831

@@ -42,7 +45,11 @@ export class CourseComponent implements OnInit, AfterViewInit {
4245

4346
this.loading = true;
4447

45-
this.coursesService.findLessons(this.course.id, "asc", 0, 3)
48+
this.coursesService.findLessons(
49+
this.course.id,
50+
"asc",
51+
this.paginator?.pageIndex ?? 0,
52+
this.paginator?.pageSize ?? 3)
4653
.pipe(
4754
tap(lessons => this.lessons = lessons),
4855
catchError(err => {
@@ -59,7 +66,20 @@ export class CourseComponent implements OnInit, AfterViewInit {
5966

6067
ngAfterViewInit() {
6168

69+
this.paginator.page
70+
.pipe(
71+
tap(() => this.loadLessonsPage())
72+
)
73+
.subscribe();
74+
6275

6376
}
6477

6578
}
79+
80+
81+
82+
83+
84+
85+

0 commit comments

Comments
 (0)