Cordova undefined in ionicPlatform.ready


#1

The below code should be working

$ionicPlatform.ready(function() {

if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}

 if(window.cordova){

 }else{
    alert('Cordova Plugin '+window.cordova)
 }
}

Can anyone please suggest some tips?


#2

Cordova is available by including its script:

<script src="cordova.js"></script>

During testing/running in the browser though it won’t be there, because it is added by packaging your app in PhoneGap.


#3

yes, it is there. I have checked it and also checked the .apk file after build. The cordova.js and cordova-plugins.js both are present.


#4

Hmm, not seeing this in my test.
What device are you testing on?


#5

thanks @mhartington for reply. I was testing on Emulator. I have found the root cause of the problem. It’s the sequence in which JS are loaded which is causing trouble. A script tag wasn’t closed in JS loading. It took me 4 days to find it. Hope it never happens to anyone :smile:


#6

How did you find that? I’m having the same issue.


#7

@alvaromb I got the solution by re doing it right from start.
Get a fresh project and check if the cordova is loaded or not. A good way to check would be to alert(window.cordova) in demo project it will surely work. Once its working. Start importing your libs in project and check at each step cordova is present or not. This should at least point you to the stage where the project is failing.