1
1
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' ;
4
4
import { openEditCourseDialog } from '../course-dialog/course-dialog.component' ;
5
5
import { filter } from 'rxjs/operators' ;
6
+ import { BreakpointObserver , Breakpoints } from '@angular/cdk/layout' ;
6
7
7
8
@Component ( {
8
9
selector : 'courses-card-list' ,
@@ -14,21 +15,60 @@ export class CoursesCardListComponent implements OnInit {
14
15
@Input ( )
15
16
courses : Course [ ] ;
16
17
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 ) {
18
27
}
19
28
20
29
ngOnInit ( ) {
21
30
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
+
22
62
}
23
63
24
- editCourse ( course :Course ) {
64
+ editCourse ( course : Course ) {
25
65
26
66
openEditCourseDialog ( this . dialog , course )
27
67
. pipe (
28
68
filter ( val => ! ! val )
29
69
)
30
70
. subscribe (
31
- val => console . log ( " new course value:" , val )
71
+ val => console . log ( ' new course value:' , val )
32
72
) ;
33
73
34
74
0 commit comments