Last active
March 19, 2018 21:56
-
-
Save sanusart/db8e7007c6fa1bd25f19183b0fd6afbc to your computer and use it in GitHub Desktop.
Angular electron/browser open link directive #angular #angular1 #angular4 #angular5 #directive #electron
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, Input } from '@angular/core'; | |
| import { ElectronService } from 'ngx-electron'; | |
| /** | |
| * @Usage: <a external href="https://www.gistoapp.com">link</a> | |
| * @dependencies: ngx-electron | |
| */ | |
| @Directive({ | |
| selector: '[external]' | |
| }) | |
| export class AnchorDirective { | |
| constructor(private electronService: ElectronService) {} | |
| @Input('href') href: string; | |
| @HostListener('click') onClick() { | |
| if (this.electronService.isElectronApp) { | |
| this.electronService.shell.openExternal(this.href); | |
| return false; | |
| } else { | |
| window.open(this.href, '_blank'); | |
| return false; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment