Detecting real time window size changes in Angular 4

后端 未结 9 749
孤独总比滥情好
孤独总比滥情好 2020-12-04 05:44

I have been trying to build a responsive nav-bar and do not wish to use a media query, so I intend to use *ngIF with the window size as a criterion. But I have

9条回答
  •  误落风尘
    2020-12-04 06:37

    You may use the typescript getter method for this scenario. Like this

    public get width() {
      return window.innerWidth;
    }
    

    And use that in template like this:

    You won't need any event handler to check for resizing/ of window, this method will check for size every time automatically.

提交回复
热议问题