Not able to use AppVersion plugin


#1

I tried using AppVersion plugin to get the version of app…but in console.log it shows the returned value as undefined…

this.platform.ready().then(() => {
            
            if (this.platform.is('cordova') ) {
                AppVersion.getVersionNumber().then( (version)=> {
                    this.appVersion = version;
                });
            }
        });
        console.log("APP VERSION :::", this.appVersion); //this gives back return

Any idea what is wring here?


#2

Your console.log is outside the function passed to the then from the Pomise.
It runs before the promise is resolved. Put it inside it, will work:

AppVersion.getVersionNumber().then( (version)=> {
	this.appVersion = version;
	console.log('App version is', version)
});