I'm using Angular 2 to make a directive. I have the following events bound to the host component:
host: {
'(mouseenter)': 'onMouseEnter($event)',
'(mouseleave)': 'onMouseLeave($event)'
}
I also created two streams and listeners on the directive to manage the two events
export class PopupDirective {
private _mouseEnterStream: EventEmitter<any> = new EventEmitter();
private _mouseLeaveStream: EventEmitter<any> = new EventEmitter();
onMouseEnter($event) {
this._mouseEnterStream.emit($event);
}
onMouseLeave($event) {
this._mouseLeaveStream.emit($event);
}
}
I want my subscribe
to only be called if the mouseenter
event is still active after a fixed delay (i.e., a mouseleave
hasn't occured). I tried doing it this way, but it doesn't work (which makes sense, I just don't know how to fix it).
this._mouseEnterStream.flatMap((e) => {
return Observable
.of(e)
.takeUntil(this._mouseLeaveStream);
}).delay(2000).subscribe(
() => console.log('yay, it worked!')
);
Does anyone with Angular 2 / RxJS experience know how I should approach this?