1

I have a page that would like to launch external app when a button is clicked and the function goToApp() should run.

Following is my code for on the ts file but everything on the page could be loaded until the point I added

import { AppLauncher, AppLauncherOptions } from '@ionic-native/app-launcher/ngx';

Which right after it the page doesn't load anymore. There is no error code returned. Any idea? Thanks in advance.

import { Component,OnInit,Input } from '@angular/core';
import { AppLauncher, AppLauncherOptions } from '@ionic-native/app-launcher/ngx';
import { ModalController, Platform } from '@ionic/angular';
import { DomSanitizer,SafeResourceUrl } from '@angular/platform-browser';
/*
  Generated class for the Posts page.

  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/

@Component({
  selector: 'page-fsfastcheck',
  templateUrl: 'fsfastcheck.html',
  styleUrls: ['fsfastcheck.scss'],
})


export class FSFastCheckPage implements OnInit {
  @Input()
  url: string = "https://eastchenconsultancy.com/feng-shui-fast-check/";
  url2: string = "https://eastchenconsultancy.com/appointment-list/";
  urlSafe: SafeResourceUrl;
  urlSafe2: SafeResourceUrl;
  mySegment: string = 'travelrequest';

  constructor(
      public modalView: ModalController,
      public sanitizer: DomSanitizer,
      private appLauncher: AppLauncher, private platform: Platform) { }

      ngOnInit() {
        this.urlSafe= this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
        this.urlSafe2= this.sanitizer.bypassSecurityTrustResourceUrl(this.url2);
      }

      close() {
        this.modalView.dismiss();
      }

      goToApp() {
        const options: AppLauncherOptions = { }

        if(this.platform.is('ios')) {
          options.packageName = 'com.apple.compass'
        } else {
          options.packageName = 'com.gn.android.compass'
        }

        this.appLauncher.canLaunch(options)
          .then((canLaunch: boolean) => console.log('Compass is available'))
          .catch((error: any) => console.error('Compass is not available'));
        }


}
Calvin Seng
  • 193
  • 1
  • 19
  • Can you add a minimal, reproducible code example, maybe in [stackblitz](https://stackblitz.com) ? Please go through https://stackoverflow.com/help/minimal-reproducible-example – Sebin Benjamin Jul 02 '19 at 00:31

1 Answers1

1

Have you followed the standard part which you need to do when adding new modules to your app:

Basically, you need to inject the module into the app:

// app.module.ts
import { AppLauncher } from '@ionic-native/app-launcher/ngx';

...

@NgModule({
  ...

  providers: [
    ...
    AppLauncher
    ...
  ]
  ...
})
export class AppModule { }
rtpHarry
  • 13,019
  • 4
  • 43
  • 64