4

I have two elements. When one element is hovered another element's one class should be removed.

import {Component} from '@angular/core'

@Component({
    selector:'display'
    template:`

     <div #myname />
     <p class="DN"> My name is Dude...</p>

    `

})
 export class DisplayComponent{
}

When div is hovered the class DN of p tag should be removed.

1 Answer 1

9

You could leverage the NgClass directive and the mouseenter and mouseleave events:

import {Component} from '@angular/core'

@Component({
    selector:'display'
    template:`

     <div (mouseenter)="showDNClass = false" (mouseleave)="showDNClass = true" #myname />
     <p [ngClass]="{ 'DN': showDNClass }"> My name is Dude...</p>

    `

})
export class DisplayComponent {
    private showDNClass: boolean = true;
}

See Plunker for example usage

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.