Created
March 12, 2018 21:38
-
-
Save javiergamarra/fbfb523ce3bcc3e651d853740d86752b to your computer and use it in GitHub Desktop.
Observable.fromEvent in angular5
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-hola', | |
template: ` | |
<p> | |
hola works! | |
<button #hola>Hola!</button> | |
</p> | |
`, | |
styleUrls: ['./hola.component.css'] | |
}) | |
export class HolaComponent implements AfterViewInit { | |
@ViewChild('hola') 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