Skip to content

Instantly share code, notes, and snippets.

@sanusart
Last active March 19, 2018 21:56
Show Gist options
  • Select an option

  • Save sanusart/db8e7007c6fa1bd25f19183b0fd6afbc to your computer and use it in GitHub Desktop.

Select an option

Save sanusart/db8e7007c6fa1bd25f19183b0fd6afbc to your computer and use it in GitHub Desktop.
Angular electron/browser open link directive #angular #angular1 #angular4 #angular5 #directive #electron
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