Skip to content

Instantly share code, notes, and snippets.

@WouterSpaak
Last active November 9, 2018 13:37
Show Gist options
  • Save WouterSpaak/cf3ed9518cffbe4b530125bfd518d4f9 to your computer and use it in GitHub Desktop.
Save WouterSpaak/cf3ed9518cffbe4b530125bfd518d4f9 to your computer and use it in GitHub Desktop.
import { HostListener } from '@angular/core';
import { UnaryFunction, Observable } from 'rxjs';
export function ObservableHostListener(
eventName: string,
args?: string[],
operator?: UnaryFunction<Observable<any>, Observable<any>>
): PropertyDecorator {
// Calling HostListener will return a decorator, ready to
// be used by TypeScript.
const preparedDecorator: (target: any, key: string) => void = HostListener(eventName, args);
// Returning a PropertyDecorator here, in which preparedDecorator
// will have to be called to register the event name with Angular's
// change detection mechanism.
return (target: any, key: string) => {
// what to do here?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment