Check if running as “ionic serve” to use a conditional in the program

≡放荡痞女 提交于 2019-12-05 03:42:54
sebaferreras

See the Platform doc:

Check if it is running on a real device or a regular browser.

You can use the platform information in order to do so:

Platform Name   Description
android         on a device running Android.
cordova         on a device running Cordova.
core            on a desktop device.
ios             on a device running iOS.
ipad            on an iPad device.
iphone          on an iPhone device.
mobile          on a mobile device.
mobileweb       in a browser on a mobile device.
phablet         on a phablet device.
tablet          on a tablet device.
windows         on a device running Windows.

So you can do something like this:

import { Platform } from 'ionic-angular';

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

    if (this.platform.is('mobileweb') || this.platform.is('core')) {
      // This will only print when running on desktop
      console.log("I'm a regular browser!");
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!