Last active
February 12, 2020 03:55
-
-
Save techiediaries/d48cf8e286c6294cd2ad9f46fbbc48f0 to your computer and use it in GitHub Desktop.
Angular 9 fromEvent example
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
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core'; | |
import {Observable} from 'rxjs/Observable'; | |
import 'rxjs/add/observable/fromEvent'; | |
@Component({ | |
selector: 'app', | |
template: ` | |
<p> | |
App works! | |
<button #btn> Click </button> | |
</p> | |
`, | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent implements AfterViewInit { | |
@ViewChild('el') button: ElementRef; | |
ngAfterViewInit() { | |
Observable.fromEvent(this.button.nativeElement, 'click') | |
.subscribe(res => console.log(res)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment