Created
February 12, 2018 18:59
-
-
Save adrianfaciu/f500be501d53e27a7df0534dd36e5929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, HostListener, ElementRef } from '@angular/core'; | |
import { Router } from '@angular/router'; | |
import { isNil } from 'ramda'; | |
@Directive({ | |
selector: 'a[appExternalUrl]', | |
}) | |
export class ExternalUrlDirective { | |
constructor(private el: ElementRef, private router: Router) {} | |
@HostListener('click', ['$event']) | |
clicked(event: Event) { | |
const url = this.el.nativeElement.href; | |
if (isNil(url)) { | |
return; | |
} | |
this.router.navigate(['/externalRedirect', { externalUrl: url }], { | |
skipLocationChange: true, | |
}); | |
event.preventDefault(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment