fromEvent(window, 'resize').subscribe(() => { this.showList = false; });
这个是监听页面长宽是否改变。
还可以这样用:
private _mouseUp: Observable<{} | Event> = merge(
fromEvent(document, 'mouseup'),
fromEvent(document, 'touchend'),
fromEvent(document, 'touchcancel')
).pipe(share());
也还可以这样:
const mouseUp = fromEvent<MouseEvent>(document, 'mouseup');
mouseUp.subscribe(_ => {
this.active = false;
if (this.changeDetector) {
this.changeDetector.detectChanges();
}
});
网友评论