Skip to content

Commit 7c29b79

Browse files
author
Your Name
committed
Angular Material In Depth
1 parent 50c1e4d commit 7c29b79

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

src/app/courses-card-list/courses-card-list.component.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@
2020
max-width: 442px;
2121
}
2222

23+
.handset-portrait .course-card {
24+
width: 100%;
25+
margin: 0;
26+
padding: 16px 0;
27+
}
28+
29+
.handset-portrait .course-thumbnail {
30+
width: 100%;
31+
margin: 0;
32+
}
33+
34+
.handset-portrait .long-description {
35+
padding: 10px 10px 0 10px;
36+
}
37+

src/app/courses-card-list/courses-card-list.component.html

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

22

3-
<mat-grid-list [cols]="2" [rowHeight]="'500px'">
3+
<mat-grid-list [cols]="cols" [rowHeight]="rowHeight"
4+
[ngClass]="{'handset-portrait': handsetPortrait}">
45

56
<mat-grid-tile *ngFor="let course of courses">
67

src/app/courses-card-list/courses-card-list.component.ts

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {Component, Input, OnInit, ViewEncapsulation} from '@angular/core';
2-
import {Course} from "../model/course";
3-
import { MatDialog, MatDialogConfig } from "@angular/material/dialog";
2+
import {Course} from '../model/course';
3+
import {MatDialog, MatDialogConfig} from '@angular/material/dialog';
44
import {openEditCourseDialog} from '../course-dialog/course-dialog.component';
55
import {filter} from 'rxjs/operators';
6+
import {BreakpointObserver, Breakpoints} from '@angular/cdk/layout';
67

78
@Component({
89
selector: 'courses-card-list',
@@ -14,21 +15,60 @@ export class CoursesCardListComponent implements OnInit {
1415
@Input()
1516
courses: Course[];
1617

17-
constructor(private dialog: MatDialog) {
18+
cols = 3;
19+
20+
rowHeight = '500px';
21+
22+
handsetPortrait = false;
23+
24+
25+
constructor(private dialog: MatDialog,
26+
private responsive: BreakpointObserver) {
1827
}
1928

2029
ngOnInit() {
2130

31+
this.responsive.observe([
32+
Breakpoints.TabletPortrait,
33+
Breakpoints.TabletLandscape,
34+
Breakpoints.HandsetPortrait,
35+
Breakpoints.HandsetLandscape
36+
])
37+
.subscribe(result => {
38+
39+
this.cols = 3;
40+
this.rowHeight = "500px";
41+
this.handsetPortrait = false;
42+
43+
const breakpoints = result.breakpoints;
44+
45+
if (breakpoints[Breakpoints.TabletPortrait]) {
46+
this.cols = 1;
47+
}
48+
else if (breakpoints[Breakpoints.HandsetPortrait]) {
49+
this.cols = 1;
50+
this.rowHeight = "430px";
51+
this.handsetPortrait = true;
52+
}
53+
else if (breakpoints[Breakpoints.HandsetLandscape]) {
54+
this.cols = 1;
55+
}
56+
else if (breakpoints[Breakpoints.TabletLandscape]) {
57+
this.cols = 2;
58+
}
59+
60+
});
61+
2262
}
2363

24-
editCourse(course:Course) {
64+
editCourse(course: Course) {
2565

2666
openEditCourseDialog(this.dialog, course)
2767
.pipe(
2868
filter(val => !!val)
2969
)
3070
.subscribe(
31-
val => console.log("new course value:", val)
71+
val => console.log('new course value:', val)
3272
);
3373

3474

0 commit comments

Comments
 (0)