Arshad Mehmood

Search the blog

    Add a Window Resize event listener for a component

    angular21 min read

    Register a window resize event listener within a component:

    @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
    host: {
    '(window:resize)': 'onResize($event)'
    }
    })
    export class AppComponent{
    onResize(event){
    console.log(event.target.innerWidth); // window width
    }
    }

    There are other ways also, I got the answer from here.