Last active
April 2, 2017 16:57
-
-
Save matthieu-D/c56ce33e844b1f6e6d692149c31bb83b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ElementRef, Renderer, ViewChild, Component} from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
constructor (private renderer: Renderer){ } | |
@ViewChild('ulEl') ulEl: ElementRef; | |
ngOnInit() { | |
this.tmpListener = this.renderer.listen(this.ulEl.nativeElement, 'click', this.logElement); | |
} | |
// Shorthand to get event.target | |
logElement({target}) { | |
if(target && target.nodeName == "LI") { | |
console.log('Target id: ', target.id); | |
// Add Business Logic here | |
} | |
} | |
ngOnDestroy() { | |
this.tmpListener(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment