distante distante - 1 year ago 161
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download