Angular2 get window width onResize

后端 未结 3 1917
广开言路
广开言路 2021-02-02 08:40

Trying to figure out how to get window width on resizing events in Angular2. Here is my code:

export class SideNav {

    innerWidth: number;

    constructor(pr         


        
3条回答
  •  有刺的猬
    2021-02-02 09:05

    onResize(event) {
      event.target.innerWidth; 
    }
    

    to get notified on scroll events on a child element in a components template

    or listen on the components host element itself

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

提交回复
热议问题