# Add a Window Resize event listener for a component

> Register a window resize event listener within a component: There are other ways also, I got the answer from here.

- Canonical: https://preview.arshadmehmood.com/today-i-learned/angular2/add-window-resize-event-listener-comopnent/
- Section: angular2
- Author: Arshad Mehmood

Register a window resize event listener within a component: 

```ts
@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](https://stackoverflow.com/questions/35527456/angular-window-resize-event).

