ionic 2 error cordova not available

后端 未结 5 1949
Happy的楠姐
Happy的楠姐 2020-12-03 02:57

I am trying to use the cordova GooglePlus plugin in a new ionic 2 project (latest ionic2 version) but I always run into errors regarding cordova. The plugin is properly inst

5条回答
  •  清歌不尽
    2020-12-03 03:17

    This error usually occurs when you're running the app in chrome using ionic serve which is normal as in the browser cordova native components are not there but also occur on emulator and devices when an ionic native plugin that you're using was nod added, even if you have added the ionic plugin for it.

    For instance if you are using native Toast

    then you need to add proper ionic dependencies:

    ionic plugin add cordova-plugin-x-toast --save
    

    but you also need to add cordova dependencies:

    cordova plugin add cordova-plugin-x-toast --save
    

    If you forget to add the later cordova plugin you'll get an error like:

    Runtime Error Uncaught(in promise): cordova_not_available
    

    Which can be tricky to find the cause.

    Once you have added ionic and cordova dependencies you should be able to use it.

    Make sure you import it:

    import { Toast } from 'ionic-native';
    

    inject Platform in constructor:

    constructor(public navCtrl: NavController, private platform: Platform) {...
    

    then use the native item:

    this.platform.ready().then(() =>
          Toast.show("Successfull", '5000', 'center')
            .subscribe(
            toast => {
              console.log(toast);
            }
          ));
    

提交回复
热议问题