Skip to content

Instantly share code, notes, and snippets.

@neilbo
Created July 3, 2018 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilbo/e297999a71014d40589b9a5c21c6be99 to your computer and use it in GitHub Desktop.
Save neilbo/e297999a71014d40589b9a5c21c6be99 to your computer and use it in GitHub Desktop.
Angular Browser Provider (Ionic)
import { Injectable } from '@angular/core';
import {
InAppBrowser,
InAppBrowserOptions
} from "@ionic-native/in-app-browser";
import { Platform } from "ionic-angular";
@Injectable()
export class BrowserProvider {
constructor(private browser: InAppBrowser,
public platform: Platform) {
console.log('Hello BrowserProvider Provider');
}
openInAppBrowser(url: string) {
const options: InAppBrowserOptions = {};
const browser = this.browser.create(url, "_blank", options);
}
openSystemBrowser(url: string) {
const options: InAppBrowserOptions = {};
const browser = this.browser.create(url, "_system", options);
}
openLink(url: string) {
if (this.platform.is('cordova')) {
this.openInAppBrowser(url);
} else if (this.platform.is('mobileweb') || this.platform.is('core') ) {
this.openSystemBrowser(url);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment