Import Keyboard depending on device


#1

Hello everybody,

I’m facing an issue in my current development with Ionic 3.
I first developped a desktop application which is working very well, but soon after i started to compile the application for IOS and ANDROID.

The problem i have is that i want to load the Keyboard component only when i run the mobile application (not in desktop browser). Obviously, if i try to load the Keyboard component in a web browser i got the message “Error: No provider for Keyboard!”.

Is there any way to load a component depending on the device ?

Something like :
if (this.platform.is(‘cordova’)) {
import { Keyboard } from ‘@ionic-native/keyboard’;
}

Thanks a lot for the help !


#2

If the error you’re getting is “Error: No provider for Keyboard!” then the issue isn’t related to the browser.

You need to import Keyboard into the providers section in app.module.ts.

After that it’ll work fine in the browser and on mobile.


#3

Maybe this article will help you: https://coryrylan.com/blog/angular-tips-dynamic-module-imports-with-the-angular-cli


#4

Thank you for your answers :wink:
Importing Keyboard to provided did the trick !


#5

Don’t forget to ‘like’ or mark as ‘solution’ where appropriate.