Angular 2: Get reference to a directive used in a component
I want to change img src on hover.for reference go through this link:--
Angular 2: Get reference to a directive used in a component
I want to change img src on hover.for reference go through this link:--
You can use mouseenter and mouseout on host element as shown below,
Look at working demo : https://plnkr.co/edit/GfgZ46?p=preview
//our root app component
import {Component, Directive, Output, EventEmitter, Input, SimpleChange} from 'angular2/core'
@Component({
selector: 'my-app',
host: {
'(mouseenter)':'MouseEnter()'
'(mouseout)':'MouseOut()'
},
template: `
<img [src]="source"/>
`
})
export class App {
source='images/angular.png';
MouseEnter(){
console.log('Hovering');
this.source = 'images/car.png';
}
MouseOut(){
this.source='images/angular.png';
}
}