简体   繁体   English

单击 ionic 5 中的硬件后退按钮退出应用程序的逻辑中的编译错误

[英]Compilation error in the logic of exiting an App on click of hardware back button in ionic 5

I have created an App with following Details - Ionic version - 5.4.16 Cordova version - 11.0.0 Angular CLI - 14.2.3 typescript - 4.8.3 npm - 8.15.0 node - 16.17.0我创建了一个具有以下详细信息的应用程序 - 离子版本 - 5.4.16 Cordova 版本 - 11.0.0 Angular CLI - 14.2.3 typescript - 4.8.3 npm - 8.15.0 节点 - 16.17.0

I want to exit an App on click of hardware back button.我想在单击硬件后退按钮时退出应用程序。 I have written below logic to exit the App - navigator["app"].exitApp();我在下面编写了退出应用程序的逻辑 - navigator["app"].exitApp();

But this logic is giving me compilation error -但是这个逻辑给我编译错误 -

var navigator: Navigator Element implicitly has an 'any' type because expression of type '"app"' can't be used to index type 'Navigator'. var navigator: Navigator 元素隐式具有“any”类型,因为“app”类型的表达式不能用于索引类型“Navigator”。 Property 'app' does not exist on type 'Navigator'. “Navigator”类型上不存在属性“app”。

This is the compilation error image这是编译错误图片

Please help me with the solution to this error or any other way to exit an App using hardware back button in ionic 5 and cordova.请帮助我解决此错误或使用 ionic 5 和 cordova 中的硬件后退按钮退出应用程序的任何其他方式。

Thanks谢谢

  navigator.app.exitApp();

in our code we do it with this line, so I think you might have the wrong syntax.在我们的代码中,我们用这一行来做,所以我认为你的语法可能有误。 I believe app is a property of navigator, you can check with a debugger.我相信应用程序是导航器的属性,您可以使用调试器进行检查。 Also, are you using typeScript?另外,您使用的是 typeScript 吗? That seems like a typescript error.这似乎是一个 typescript 错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM