@@ -45,18 +45,19 @@ export class BreakpointObserver implements OnDestroy {
4545 * @returns Whether any of the media queries match.
4646 */
4747 isMatched ( value : string | string [ ] ) : boolean {
48- let queries = coerceArray ( value ) ;
48+ const queries = splitQueries ( coerceArray ( value ) ) ;
4949 return queries . some ( mediaQuery => this . _registerQuery ( mediaQuery ) . mql . matches ) ;
5050 }
5151
5252 /**
5353 * Gets an observable of results for the given queries that will emit new results for any changes
5454 * in matching of the given queries.
55+ * @param value One or more media queries to check.
5556 * @returns A stream of matches for the given queries.
5657 */
5758 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 ) ;
6061
6162 return combineLatest ( observables , ( a : BreakpointState , b : BreakpointState ) => {
6263 return {
@@ -72,9 +73,9 @@ export class BreakpointObserver implements OnDestroy {
7273 return this . _queries . get ( query ) ! ;
7374 }
7475
75- let mql : MediaQueryList = this . mediaMatcher . matchMedia ( query ) ;
76+ const mql : MediaQueryList = this . mediaMatcher . matchMedia ( query ) ;
7677 // Create callback for match changes and add it is as a listener.
77- let queryObservable = fromEventPattern (
78+ const queryObservable = fromEventPattern (
7879 // Listener callback methods are wrapped to be placed back in ngZone. Callbacks must be placed
7980 // back into the zone because matchMedia is only included in Zone.js by loading the
8081 // webapis-media-query.js file alongside the zone.js file. Additionally, some browsers do not
@@ -93,8 +94,18 @@ export class BreakpointObserver implements OnDestroy {
9394 ) ;
9495
9596 // Add the MediaQueryList to the set of queries.
96- let output = { observable : queryObservable , mql : mql } ;
97+ const output = { observable : queryObservable , mql : mql } ;
9798 this . _queries . set ( query , output ) ;
9899 return output ;
99100 }
100101}
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