@@ -45,18 +45,19 @@ export class BreakpointObserver implements OnDestroy {
45
45
* @returns Whether any of the media queries match.
46
46
*/
47
47
isMatched ( value : string | string [ ] ) : boolean {
48
- let queries = coerceArray ( value ) ;
48
+ const queries = splitQueries ( coerceArray ( value ) ) ;
49
49
return queries . some ( mediaQuery => this . _registerQuery ( mediaQuery ) . mql . matches ) ;
50
50
}
51
51
52
52
/**
53
53
* Gets an observable of results for the given queries that will emit new results for any changes
54
54
* in matching of the given queries.
55
+ * @param value One or more media queries to check.
55
56
* @returns A stream of matches for the given queries.
56
57
*/
57
58
observe ( value : string | string [ ] ) : Observable < BreakpointState > {
58
- let queries = coerceArray ( value ) ;
59
- let observables = queries . map ( query => this . _registerQuery ( query ) . observable ) ;
59
+ const queries = splitQueries ( coerceArray ( value ) ) ;
60
+ const observables = queries . map ( query => this . _registerQuery ( query ) . observable ) ;
60
61
61
62
return combineLatest ( observables , ( a : BreakpointState , b : BreakpointState ) => {
62
63
return {
@@ -72,9 +73,9 @@ export class BreakpointObserver implements OnDestroy {
72
73
return this . _queries . get ( query ) ! ;
73
74
}
74
75
75
- let mql : MediaQueryList = this . mediaMatcher . matchMedia ( query ) ;
76
+ const mql : MediaQueryList = this . mediaMatcher . matchMedia ( query ) ;
76
77
// Create callback for match changes and add it is as a listener.
77
- let queryObservable = fromEventPattern (
78
+ const queryObservable = fromEventPattern (
78
79
// Listener callback methods are wrapped to be placed back in ngZone. Callbacks must be placed
79
80
// back into the zone because matchMedia is only included in Zone.js by loading the
80
81
// webapis-media-query.js file alongside the zone.js file. Additionally, some browsers do not
@@ -93,8 +94,18 @@ export class BreakpointObserver implements OnDestroy {
93
94
) ;
94
95
95
96
// Add the MediaQueryList to the set of queries.
96
- let output = { observable : queryObservable , mql : mql } ;
97
+ const output = { observable : queryObservable , mql : mql } ;
97
98
this . _queries . set ( query , output ) ;
98
99
return output ;
99
100
}
100
101
}
102
+
103
+ /**
104
+ * Split each query string into separate query strings if two queries are provided as comma
105
+ * separated.
106
+ */
107
+ function splitQueries ( queries : string [ ] ) : string [ ] {
108
+ return queries . map ( ( query : string ) => query . split ( ',' ) )
109
+ . reduce ( ( a1 : string [ ] , a2 : string [ ] ) => a1 . concat ( a2 ) )
110
+ . map ( query => query . trim ( ) ) ;
111
+ }
0 commit comments