I'm wondering how do you get an Observable of a Event in Angular 2?
For example I want to subscribe to a click event but only emit after two clicks? Is possible to get a Observable of
this.clickStream = new Subject();
<button (click)="clickStream.next($event)">Click Me</button>
Observable has a fromEvent operator, but to use it you'll need a reference to the native element. The way to get it is to use viewChild/contentChild to get an elementRef.
Next you can bind to its click like so:
var clickStream = Observable.fromEvent(btnRef.nativeElement, 'click');
If I understood the filtering thing properly, you want the stream to emit only after the click was pressed twice, or to be more precise, once for each 2 clicks, to do so, use the bufferWithCount operator:
var triggerFor2Clicks = clickStream.bufferWithCount(2);
This will emit an array of 2 events at a time, so your action handler can be:
triggerFor2Clicks.subscribe(() => my2ClicksHandler);
Note that the arguments are empty, notated as '()' since you don't really care for the events, just to the fact that they were 2 of them.