Reputation: 490
How we can check the mouse and key events in angular 2 globally, I meant at root level. I want to call one service when user is interacting not idle with the application. Please help me and suggest some good solution on this.
Upvotes: 3
Views: 2112
Reputation: 12376
In your top level component, create an observable from an event of a Document object and invoke your service, for example:
import 'rxjs/add/observable/fromEvent';
import {Observable} from "rxjs/Observable";
...
const clicks$ = Observable.fromEvent(document, 'click');
clicks$.subscribe(x => console.log('Calling my service here'));
Upvotes: 5