Azure & Ionic2 - WindowsAzure is not defined

Has anyone successfully got Azure and Ionic2 to play along nicely? I followed the Azure Quickstart guide for Cordova but I only get the message

WindowsAzure is not defined

In installed the azure plugin via

cordova plugin add cordova-plugin-ms-azure-mobile-apps

Then inside app.component.ts I call

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();
      console.log('test');

      client = new WindowsAzure.MobileServiceClient('https://build2016-vsmobile.azurewebsites.net/');

    });

but no luck.

If I manually refrence the script (MobileServices.Cordova.js) from the cordova plugin in my index.html file, it works… but this is bad practice to say the very lest.

I’ve been having the same problem actually and am not really sure if I should be using the plugin or using the library as talked about here

for your problem does this help at all ? See the bit about using

(<any> window).plugins.somePlugin.doSomething();

so what did you put in your index.html ?

Hi Richard, sorry for the super late reply… take a look at the github issue page of Azure mobile cordova plugin. I haven’t tried any further with Azure due to other projects, but they gave me some direction (I have to try out yet). What worked straight out of teh box for me was to take the script, that they are using inside their cordova plugin and reference it in the index.html. I guess they simply wrapped their normal library inside a cordova plugin, not sure though.

I got it to work.

1 Like

Hi Richard, cool. Thanks for letting me know!

Hi @richardshergold,

Reading through your post I manage to get my new ionic2 app work with Azure table APIs and currently struggling with setting up offline sync with local storage. Any chance you having another post or working example?

Cheers!

Hi @richardshergold - thanks a lot for that article.

I thought about it, that is, to install it locally in my app so that I can refer it in import statements in my .ts files but being new to Ionic 2 framework and TypeScript, I wasn’t sure.

Your article and link to that “Using Third Party Libraries” on Ionic’s website helped and confirmed my understanding. :slight_smile:

One thing that is mentioned by you and also in the Ionic’s link but I did not do is creating the “.d.ts” file and adding an entry for the library. I didn’t have to do that. I tried to import WindowsAzure in my .ts file from cordova-plugin-ms-azure-mobile-apps and it was able give me that as InteliSense option (which means it recognized the library without doing the “.d.ts” file part.

Thought of sharing my experience.

Thanks!

1 Like