This file contains hidden or 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
// OPTION A: "standard way" => Class | |
// In Angular example, use this snippet inside AfterViewInit lifecycle hook: | |
class MyAngularComponent implements AfterViewInit { | |
ngAfterViewInit() { | |
// Standard-way | |
document.querySelector('#clickCounter') | |
.addEventListener('counter-clicked', this.myCallbackFunction); | |
} |
This file contains hidden or 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
// OPTION B: "Angular way" => Class | |
// In Angular example, use this snippet inside AfterViewInit lifecycle hook: | |
class MyAngularComponent implements AfterViewInit { | |
// Through @ViewChild decorator, Angular will get the first element matches selector in the DOM | |
@ViewChild('counter', { static: false }) counter; | |
ngAfterViewInit() { | |
// Angular-way | |
this.counter.nativeElement |
OlderNewer