我有一个页面,它想要启动外部应用程序时,一个按钮被点击,函数goToApp()应该运行。
以下是我在ts文件上的代码,但页面上的所有内容都可以加载到我添加的位置
从‘@ionic-native/app-launcher/ngx’导入{ AppLauncher,AppLauncherOptions };
然后页面就不会再加载了。未返回错误代码。有什么想法吗?提前谢谢。
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'));
}
}
发布于 2019-07-02 11:45:38
您是否遵循了向应用程序添加新模块时需要执行的标准部分:
基本上,您需要将模块注入到应用程序中:
// app.module.ts
import { AppLauncher } from '@ionic-native/app-launcher/ngx';
...
@NgModule({
...
providers: [
...
AppLauncher
...
]
...
})
export class AppModule { }https://stackoverflow.com/questions/56836764
复制相似问题