首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ionic4硬件移动后对接问题

Ionic4硬件移动后对接问题
EN

Stack Overflow用户
提问于 2019-07-22 18:43:19
回答 1查看 404关注 0票数 1

如果单击后退按钮关闭安卓手机中的ionic4应用程序,则会收到以下错误代码以关闭应用程序:

代码语言:javascript
运行
复制
ionViewDidEnter() {
    this.subscription = this.platform.backButton.subscribe(async () => {
        navigator['app'].exitApp();
    });
}

ionViewWillLeave() {
    this.subscription.unsubscribe();
}

错误:

代码语言:javascript
运行
复制
 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!
EN

回答 1

Stack Overflow用户

发布于 2019-07-22 18:48:05

请参阅此代码段解决方法

代码语言:javascript
运行
复制
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模块。

代码语言:javascript
运行
复制
import { Platform } from '@ionic/angular';

@Component({...})
export class MyPage {
  constructor(public plt: Platform) {

  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57144286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档