Skip to content

Instantly share code, notes, and snippets.

@wesleycho
Last active February 4, 2016 18:55
Show Gist options
  • Save wesleycho/2b259ca5e06c316376ee to your computer and use it in GitHub Desktop.
Save wesleycho/2b259ca5e06c316376ee to your computer and use it in GitHub Desktop.
@Directive({
host: {
'(click)': 'goToRoute($event)',
'(keydown)': 'goToRoute($event)'
}
})
class MyRouteHandler {
@Input() route;
constructor(private _router: Router) {}
goToRoute(evt: Event | KeyboardEvent) {
if (evt.type === 'click' || (evt.type === 'keydown' && evt.keyCode === 13) {
this._router.navigate([this.route]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment