本文整理汇总了TypeScript中@angular/flex-layout.ObservableMedia.asObservable方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ObservableMedia.asObservable方法的具体用法?TypeScript ObservableMedia.asObservable怎么用?TypeScript ObservableMedia.asObservable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/flex-layout.ObservableMedia
的用法示例。
在下文中一共展示了ObservableMedia.asObservable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngOnInit
public ngOnInit() {
this.enableSideNav$ = this.media.asObservable()
.map(() =>
this.media.isActive('xs') || this.media.isActive('sm')
)
.startWith(this.media.isActive('xs') || this.media.isActive('sm'));
}
示例2: ngOnInit
ngOnInit() {
// Automatically close side menu on screens > sm breakpoint
this.media
.asObservable()
.pipe(filter((change: MediaChange) => change.mqAlias !== 'xs' && change.mqAlias !== 'sm'))
.subscribe(() => this.sidenav.close());
}
示例3: constructor
public constructor(
private readonly observableMedia: ObservableMedia,
) {
this.breakpoint = this.observableMedia.asObservable()
.startWith(null)
.combineLatest(
Observable.fromEvent(window, 'resize')
.debounceTime(100)
.startWith(null),
)
.map(([d, e]) => {
let mqAlias = d && d.mqAlias || null;
if (mqAlias == null) {
// Unknown/first-pass case, need to guess. Breakpoints based upon:
// https://github.com/angular/flex-layout/wiki/Responsive-API
mqAlias = 'xl';
if (window.innerWidth <= 600) {
mqAlias = 'xs';
} else if (window.innerWidth <= 960) {
mqAlias = 'sm';
} else if (window.innerWidth <= 1280) {
mqAlias = 'md';
} else if (window.innerWidth <= 1440) {
mqAlias = 'lg';
}
}
switch (mqAlias) {
default:
case 'xs':
return Breakpoint.XS;
case 'sm':
return Breakpoint.SM;
case 'md':
return Breakpoint.MD;
case 'lg':
return Breakpoint.LG;
case 'xl':
return Breakpoint.XL;
}
})
.publishReplay(1)
.refCount();
}
示例4: ngOnInit
ngOnInit() {
const grid = new Map([
['xs', 1],
['sm', 2],
['md', 2],
['lg', 3],
['xl', 3]
]);
let start: number;
grid.forEach((cols, mqAlias) => {
if (this.observableMedia.isActive(mqAlias)) {
start = cols;
}
});
this.cols = this.observableMedia.asObservable()
.pipe(
map(change => grid.get(change.mqAlias)),
startWith(start)
);
}