Angular2 onresize event inside div missing reference

651 Views Asked by At

currently i`m trying to find out how to handle window:onresize event in angular2. i have embedded it in a components template like this:

<div class="signaturepadContainer" (window:resize)="onResize($event)">

and handle the event in ts-file like

  onResize(event: any){ ...dosomethingterrible... }

in my 'event'-parameter i have in 'curenTarge', 'source' and 'target' reference to 'window', but not to my div.

Where am i wrong ?

1

There are 1 best solutions below

0
Günter Zöchbauer On

By adding window: you make it a global event handler. Even though you added it to a div, it's not related to this div at all. It would behave the same no matter where you add it.

You can also use

@HostListener('window:resize', ['$event'])
onResize(event: any){ ...dosomethingterrible... }

to have less confusing code.