Window.cordova is undefined in ionic

I created a blank project in ionic. In the www/js/app.js with the following code:

angular.module('starter', ['ionic', 'ngCordova'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      console.log("works!");
    }else {
      console.log("nopes");
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});

I always get nopes in the console. Why is that so? Why is window.cordova undefined?

Is cordova.js loaded ?
Other issue might be that you don’t have the keyboard plugin installed

If you mean when running in dev mode with ionic serve that’s normal, window.cordova will only be defined when running on iOS or Android.

2 Likes

Hello, Someone solve this problem? I have exact thing, cordova.js is not loaded so I have message ‘nope’ from code above. Also I use device for debugging so I should works but not…

When I open the app via Ionic View it said that window.cordova isn’t defined…

Is cordova available only when project is built and started as particular app?

Looks like u were able to see the Logs when using Ionic View . Please advise how to debug in Ionic View ?
Thanks

Android Monitor :wink: It’s in de the SDK