Currently, I am utilizing the Angular @HostListener to retrieve the current width of the viewport onResize()
in the following manner:
@HostListener('window:resize', ['$event'])
onResize(event?) {
window.innerWidth <= 400 ? this.width = 200 : this.width = 400;
}
However, I also require a method to set this.width onLoad()
of the component (either in the constructor or during the ngOnInit()
lifecycle).
I have not discovered a way to achieve this using HostListener. Is there an effective alternative to obtain the current viewport width (both on resize and onLoad) and respond accordingly?
My objective is to define the maxWidth of a Leaflet-PopUp for mobile viewport sizes.