Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 544 Bytes

add-window-resize-event-listener-comopnent.md

File metadata and controls

21 lines (18 loc) · 544 Bytes

Add a Window Resize event listener for a component

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.