I need to subscribe & do some actions, when mouseover on particular elements in the DOM.
For Example: home.component.html
<div class="container">
<div class="row1"> </div>
<div class="row2"> </div>
<div class="row3"> </div>
</div>
home.component.ts:
import {
AfterViewInit,
Component,
Input,
OnInit,
} from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
})
export class homeComponent implements OnInit {
public hover: boolean;
constructor() {}
ngOnInit(): void {
this.hover= true; // it may be false also.
}
}
In the above example when mouseover on row1 & row3 elements then I need to subscribe. Also I need to check one variable called "hover", if it is true then only I need todo the above action(mouseover). If the variable is false then no need to check for mouseover(no need to do any action), just I need to unsubscribe it. Can any one help me to achieve this.
Simply react on
mouseenter
andmouseleave
event.See this example in action: https://stackblitz.com/edit/angular-ivy-2bdafy?file=src/app/app.component.ts