This repository was archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathresponsiveFlexDirective.demo.ts
51 lines (45 loc) · 1.75 KB
/
responsiveFlexDirective.demo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {Component, OnInit, Inject, OnDestroy} from '@angular/core';
import {Subscription} from "rxjs/Subscription";
import 'rxjs/add/operator/filter';
import {MediaChange} from "../../../lib/media-query/media-change";
import {MatchMediaObservable} from "../../../lib/media-query/match-media";
@Component({
selector: 'demo-responsive-flex-directive',
styleUrls : [
'../demo-app/material2.css'
],
template: `
<md-card class="card-demo" >
<md-card-title>Responsive Flex Directives</md-card-title>
<md-card-subtitle>Use the show hide APIs to responsively show or hide elements:</md-card-subtitle>
<md-card-content>
<div class="containerX">
<div fxLayout="row" class="coloredContainerX box" >
<div fxFlex.gt-sm="67" fxFlex="33"> flex 33% on mobile, <br>and 66% on gt-sm devices. </div>
<div fxFlex.gt-sm="33" fxFlex="67"> flex 67% on mobile, <br>and 33% on gt-sm devices. </div>
</div>
</div>
</md-card-content>
<md-card-footer style="width:95%">
<div class="hint" >Active mediaQuery: <span style="padding-left: 20px; color: rgba(0, 0, 0, 0.54)">{{ activeMediaQuery }}</span></div>
</md-card-footer>
</md-card>
`
})
export class DemoResponsiveFlexDirectives implements OnInit, OnDestroy {
private _watcher : Subscription;
public activeMediaQuery = "";
constructor(@Inject(MatchMediaObservable) private _media$) { }
ngOnInit() {
this._watcher = this.watchMQChanges();
}
ngOnDestroy() {
this._watcher.unsubscribe();
}
watchMQChanges() {
return this._media$.subscribe((change:MediaChange) => {
let value = change ? `'${change.mqAlias}' = ${change.mediaQuery} )` : "";
this.activeMediaQuery = value;
});
}
}