如果单击后退按钮关闭安卓手机中的ionic4应用程序,则会收到以下错误代码以关闭应用程序:
ionViewDidEnter() {
this.subscription = this.platform.backButton.subscribe(async () => {
navigator['app'].exitApp();
});
}
ionViewWillLeave() {
this.subscription.unsubscribe();
}
错误:
E/Capacitor/Plugin/Console: ERROR Error: Uncaught (in promise): Error: StaticInjectorError[t -> t]:
StaticInjectorError(Platform: core)[t -> t]:
NullInjectorError: No provider for t!
Error: StaticInjectorError[t -> t]:
StaticInjectorError(Platform: core)[t -> t]:
NullInjectorError: No provider for t!
发布于 2019-07-22 18:48:05
请参阅此代码段解决方法
this.platform.backButton.subscribe(() => {
// code that is executed when the user pressed the back button
})
// To prevent interference with ionic's own backbutton handling
// you can subscribe with a low priority instead
this.platform.backButton.subscribeWithPriority(0, () => {
// code that is executed when the user pressed the back button
// and ionic doesn't already know what to do (close modals etc...)
})
PS:希望你能检查一下是否导入了platform
模块。
import { Platform } from '@ionic/angular';
@Component({...})
export class MyPage {
constructor(public plt: Platform) {
}
}
https://stackoverflow.com/questions/57144286
复制相似问题