When using the following code, window.cordova is not (yet) available… Its only reachable after platform.ready.
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function ($ionicPlatform, $rootScope, $state) {
$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 && window.cordova.plugins.Keyboard) {
window.cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
window.cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
window.StatusBar.styleLightContent();
}
});
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
if (toState.name !== 'login') {
console.log(window.cordova.plugins); //!!!! THIS GOES WRONG !!!!
/*
var prefs = plugins.appPreferences;
prefs.fetch('iuserid').then(function (value) {
if (value != '') {
$state.go('login');
}
});
*/
var loggedIn = false;
if (loggedIn === false) {
event.preventDefault();
$state.transitionTo('login');
}
}
});
})
Any experience with this problem??
Many thanks!