I need to apply some custom styling on an element based on the window's current screenWidth.
That's successfully done by using the following @HostListener:
@HostListener('window:resize', ['$event'])
public resize() {
// apply styles here depending on current window.innerWidth...
}
However, I want to trigger the resize method ONLY when window's width has changed and do nothing when height has changed.
The way it is so far, the resize method is also called if the user changes the window height and that is breaking my styling logic!
So my question is: Is there a way in Angular to make something like ('window:resizeX') in order to call resize() only when window width changes, ignoring changes on window height?
resizefunction. something likeprivate windowOldWidth: number = window.innerWidthandresize() { if(this.windowOldWidth === window.innerWidth) { return; } this.windowOldWidth = window.innerWidth; // rest of logic here }