如何解决检测Angular 4中的实时窗口大小变化?

在初始化时得到它

public innerWidth: any;
ngOnInit() {
    this.innerWidth = window.innerWidth;
}

如果您想在调整大小时保持更新:

@HostListener('window:resize', ['$event'])
onResize(event) {
  this.innerWidth = window.innerWidth;
}

解决方法

我一直在尝试构建一个响应式导航栏并且不希望使用媒体查询,所以我打算使用*ngIf窗口大小作为标准。但是我一直面临一个问题,因为我找不到任何关于
Angular 4 窗口大小检测的方法或文档。我也尝试过 JavaScript 方法,但不支持。

我还尝试了以下方法

constructor(platform: Platform) {
    platform.ready().then((readySource) => {
        console.log('Width: ' + platform.width());
        console.log('Height: ' + platform.height());
    });
}

…用于离子。

并且screen.availHeight,但仍然没有成功。