-
-
Save DuncanFaulkner/94a71cf6e41931f8c86891025a8eb4f1 to your computer and use it in GitHub Desktop.
mediaObserver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { MediaChange, MediaObserver } from '@angular/flex-layout'; | |
import { Observable } from 'rxjs'; | |
import { map } from 'rxjs/operators'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'], | |
}) | |
export class AppComponent implements OnInit { | |
constructor(private mediaObserver: MediaObserver) {} | |
cols: Observable<any> | undefined; | |
ngOnInit(): void { | |
const grid = new Map([ | |
['xs', 1], | |
['sm', 2], | |
['md', 3], | |
['lg', 4], | |
['xl', 5], | |
]); | |
this.cols = this.mediaObserver.asObservable().pipe( | |
map((change: MediaChange[]) => { | |
console.log(change[0]); | |
console.log(grid.get(change[0].mqAlias)); | |
return grid.get(change[0].mqAlias); | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment