【问题标题】:Error while using Azure Mobile Apps - Javascript Client SDK使用 Azure 移动应用时出错 - Javascript 客户端 SDK
【发布时间】:2016-11-25 09:56:39
【问题描述】:

我正在开发 ionic 移动应用。我已经关注了这些文件https://github.com/azure/azure-mobile-apps-js-clienthttps://github.com/azure-appservice-samples/ContosoMoments/tree/master/src

当我在控制器中注入“mobileServicesClient”时,出现未知提供程序错误。 如果我直接在这样的函数中使用

var clientRef = new MobileServiceClient('https://******.azurewebsites.net');
clientRef.login('aad').then(function(result){ console.log(result); },function(result){ console.log(result); }

我收到错误:'MobileServiceClient 未定义'

【问题讨论】:

    标签: javascript ionic-framework azure-mobile-services azure-ad-b2c


    【解决方案1】:

    在使用对象之前添加脚本引用。

    <script src="https://zumo.blob.core.windows.net/sdk/azure-mobile-apps-client.2.0.0-rc1.js"></script>
    

    并使用正确的命名空间

    var clientRef = new WindowsAzure.MobileServiceClient('https://...');
    

    【讨论】:

    • 我也尝试过使用 WindowsAzure。但它给出了相同的错误 WindowsAzure 未定义。我使用了 azure-mobile-apps-client.js 而不是 azure-mobile-apps-client.2.0.0-rc1.js。它们之间有什么区别吗?在 github 上,我发现它(不是 2.0.0)是最新的。
    • 似乎这个库还没有发布。请参阅 npm npm show azure-mobile-apps-client version 中的 lib 版本 - 它显示现在只有 2.0.0-rc1 可用。所以看来你还不能使用严格的'2.0.0'。
    • 除了来自@VadimB 的出色评论外,您还不得在页面加载之前引用 MobileServiceClient。 - 我不是 Ionic 专家,但我相信在 $ionicPlatform.ready() 的回调中引用是合适的。
    【解决方案2】:

    当您使用 ionic 框架来实现您的客户端应用程序时,您可以尝试使用Apache Cordova plugin for Azure Mobile Apps 作为客户端 SDK。

    尤其是基于 ionic 的应用程序,您可以参考 https://github.com/Microsoft/azure-mobile-apps-with-ionic 了解使用 ionic 的 azure 移动应用程序的入门示例项目。

    如有任何进一步的问题,请随时告诉我。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 1970-01-01
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多