Detecting real time window size changes in Angular 4

后端 未结 9 746
孤独总比滥情好
孤独总比滥情好 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:34

    @HostListener("window:resize", [])
    public onResize() {
      this.detectScreenSize();
    }
    
    public ngAfterViewInit() {
        this.detectScreenSize();
    }
    
    private detectScreenSize() {
        const height = window.innerHeight;
        const width = window.innerWidth;
    }
    

提交回复
热议问题