ttmt
ttmt

Reputation: 4984

Angular get window size onload

I can do this to get the window size on resizing

@HostListener('window:resize', ['$event']) resizeHandler(event: any) { this.isSmallScreen = event.target.innerWidth > 600; }

How can I get the window size on load

If the page loads when the screen size is > 600 I need isSmallScreen to true,

I still need the window on resize but I need the size when the page loads as well

Upvotes: 0

Views: 3105

Answers (1)

ttmt
ttmt

Reputation: 4984

ngOnInit() {
    this.isSmallScreen = (window.innerWidth) > 600;
}

Upvotes: 2

Related Questions