I use ionic serve
to run my app on localhost.
how can I know when I'm in browser and not in android?
I tried:
navigator.platform // MacIntel navigator.platforms // undefined ionic.Platform.is('BROWSER') // false navigator.userAgent // ...iPhone... => i'm in chrome device mode
Thank you!
Developer Options & USB Debugging are enabled by default in the Android emulator. Open the Chrome browser and navigate to the URL chrome://inspect/#devices . Your connected Android device should show up in the list of Remote Targets. On your device, open the Ionic app that you would like to debug using Chrome.
By default, ionic serve boots up a development server on localhost . To serve to your LAN, specify the --external option, which will use all network interfaces and print the external address(es) on which your app is being served. Try the --lab option to see multiple platforms at once. ionic serve uses the Angular CLI.
There's probably more than one way to do it, but a simple one is that cordova
will only be defined on Android/iOS so you could do
if (window.cordova) { // running on device/emulator } else { // running in dev mode }
Some text editors and TypeScript parsers may complain that Property 'cordova' does not exist on type 'Window'.
In order to work around that, you can use the following:
if ((<any>window).cordova) { // running on device/emulator } else { // running in dev mode }
By explicitly casting to type any
you can avoid transpiler errors, and still accomplish what you're trying to do.
I found I can use
ionic.Platform.platforms[0] == "browser"
to check if the application is running in a browser or not.
Important thing, ionic.Platform.platforms
is set only after $ionicPlatform.ready
event is fired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With