2016-06-14 27 views
1

已創建基於Ionic2空白模板的Ionic2應用程序。使用Visual Studio 2015更新2.已將Azure移動服務帳戶設置爲後端。已安裝Azure的移動應用插件(加倍點擊config.xml並選擇Azure的移動應用程序,然後點擊安裝)/config.xml摘錄:修復WindowsAzure未在Ionic2/Angular2應用程序中定義

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

已經安裝了蔚移動app.d.ts如下所述: https://www.nuget.org/packages/azure-mobile-apps.TypeScript.DefinitelyTyped/。 VS2015 intellisense認爲代碼有效。

但是,在試圖訪問Chrome控制檯中的後端時出現錯誤:WindowsAzure未定義。

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

回答

1

代碼需要在設備準備就緒後運行。在Ionic2你可以看到設備準備的一個例子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(); 
    }); 
    } 

我誤以爲設備就緒後,主頁構造函數開火,但事實並非如此。

1

我已經能夠得到WindowsAzure.MobileServiceClient工作的唯一辦法是在我的供應商聲明WindowsAzure變量,然後手動包括腳本文件MobileServices.Cordova.js在index.html的腳本引用。這並不理想。這裏有一些打字文件,但它們不是最新的。

+2

我也很長時間尋找最新的支持類型,但找不到任何。作爲解決方法,我在此處使用Microsoft Ionic 2和Azure應用服務示例項目中的類型: https://github.com/Microsoft/build2016-vsmobile /typings/manual/azure-mobile-app.d .TS –

相關問題