javascript - Angular Add/Remove class on mouseOvered from the .ts file -


i using angular 4 , have div on html template:

<div [class.mycssclass]="mouseovered" (mouseout)="mouseovered=false" (mouseover)="mouseovered=true">hover me</div> 

this works great same thing .ts component file instead.

how can .ts component file?

according me, best way use hostlistener.

for component listen on on mouse events can use:

@component({   selector: 'my-component'   template: '<div [class.mycssclass]="mouseover"' }) class mycomponent {      mouseover:boolean;      @hostlistener('mouseover')     onmouseover() {         this.mouseover = true;     }      @hostlistener('mouseout')     onmouseout() {         this.mouseover = false;     }  } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -