distante distante - 2 months ago 19
AngularJS Question

How to wrap cordova getAppVersion on a variable promise?

I have this code:

var promiseVersionNumber;
if (typeof cordova !== 'undefined') {
console.log("I have cordova, I will try to get the AppversionNumeber");
promiseVersionNumber = cordova.getAppVersion.getVersionNumber();
} else {
console.warn("There is no cordova, I will use a dummyAppVersion");
promiseVersionNumber = $q.when(dummyAppVersion);

return $q.when(
defaultConfig.version = versionNumber;
return dbAppInfo.put(defaultConfig);
console.log("appConfig was created and saved on Database");

return dbAppInfo.put({
_id: 'myLastUpdate',
myLastUpdate: today,
debug: todayDebug
console.error("There was an error while initAppConfig appConfig on Database");
return error;

In browser with my dummy
all works ok, but on device I get this error:

TypeError: promiseVersionNumber.then(...).then(...).then(...).catch is not a function

How can I correctly wrap


Just use ngCordova, that would be the easy way. http://ngcordova.com/docs/plugins/appVersion/