Ionic2 RC4 AppVersion error


#1

My code is:
AppVersion.getVersionNumber().then(data => {

    });

I got an error while running “ionic serve”:


AppVersion
#2

It’s because AppVersion is a cordova only plugin, therefore it will not work on browsers. Wrap your code inside a platform.ready().then(() => { });

like this:

platform.ready().then(() => { AppVersion.getVersionNumber().then(data => { }); });

EDIT:
Also make sure to inject platform in the constructor:
import {Platform} from 'ionic-angular'; ... constructor(public platform: Platform) ...


#3

My code is already inside “platform.ready()”, I also use Toast plugin, it works well.


#4

Oh right. Sorry. You need to do this:
if(platform.is('cordova')) { ... }

The problem is that the cordova interface is not ready. And the platform.ready runs on regular browsers as well. The AppVersion will not work during serve, only on devices or simulators. My bad there.


#6

I works! Thank you very much~~