2017-08-10 90 views
-1

我需要檢查窗口大小,如果它是< 1400像素(筆記本電腦),什麼是最好的辦法呢?檢查窗口大小角度2

如果它小於1400,我想設置一個變量爲true例如。

+0

也許這將有助於https://stackoverflow.com/questions/35527456/angular-window-resize-event – 0mpurdy

+0

也許你應該檢查響應設計,如果你想適應你的html不同的大小。據我所知可以通過css – JohnnyAW

+0

@JohnnyAW來完成,如果<1400px,我需要將devex grid的pageSize設置爲5,這就是爲什麼我需要這種類型的檢查。 – grabnem

回答

1

你可以得到這些值這樣的:

constructor() { 
    // User screen size 
    const screenHeight = window.screen.height; 
    const screenWidth = window.screen.width; 

    // Actual space available in navigator 
    const actualHeight = window.innerHeight; 
    const actualWidth = window.innerWidth; 
} 

但是,如果用戶調整它的窗口,這是不會改變。

您可以通過使用HostListener得到這些新的價值觀:

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

當調整導航器的窗口在onResize將被調用。我可能很經常,你可能需要一個Subject來處理它。