Matthew
Matthew

Reputation: 3071

Fix WindowsAzure is not defined in Ionic2 / Angular2 App

Have created an Ionic2 app based on the Ionic2 blank template. Using Visual Studio 2015 Update 2. Have setup Azure Mobile Services account to use as the backend. Have installed Azure Mobile Apps plugin (by doubling clicking config.xml and choosing Azure Mobile Apps and clicking install) /config.xml excerpt:

<plugin name="cordova-plugin-ms-azure-mobile-apps" version="2.0.0-beta4" />

Have installed azure-mobile-app.d.ts as described here: https://www.nuget.org/packages/azure-mobile-apps.TypeScript.DefinitelyTyped/. VS2015 intellisense considers code valid.

However, getting an error when trying to access the backend in chrome console: WindowsAzure is not defined.

client: WindowsAzure.MobileServiceClient;
...
client = new WindowsAzure.MobileServiceClient('removed url for security');

Upvotes: 1

Views: 640

Answers (2)

Corey Roth
Corey Roth

Reputation: 1126

The only way I have been able to get WindowsAzure.MobileServiceClient to work is by declaring a WindowsAzure variable in my provider and then manually include the script file MobileServices.Cordova.js as a script reference in index.html. It's less than ideal. There are some typing files out there for it but they aren't up to date any more.

Upvotes: 1

Matthew
Matthew

Reputation: 3071

Code needs to be run after device ready. In Ionic2 you can see an example of device ready in app.ts:

constructor(platform: Platform) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
    });
  }

I mistakenly thought the home page constructor would fire after device ready but it does not.

Upvotes: 1

Related Questions