简体   繁体   English

如何将Azure移动服务连接到离子应用程序

[英]How to connect azure mobile services to ionic application

I have created a very simple ionic application with a login and username so far. 到目前为止,我已经使用登录名和用户名创建了一个非常简单的离子应用程序。 I am currently using Microsoft azure mobile services to host my application. 我目前正在使用Microsoft azure移动服务来托管我的应用程序。 However I don't know how to work with a php file and a server. 但是我不知道如何使用php文件和服务器。 I am a beginner with working with servers thank you in advance. 我是使用服务器的初学者,谢谢。

PHP Code: PHP代码:

<?php
try {
    $conn = new PDO("microsoft azure connection string", "username", "password");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
    print("Error connecting to SQL Server.");
    die(print_r($e));
}

?>

login controller : 登录控制器:

 .controller('loginCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
    // You can include any angular dependencies as parameters for this function
    // TIP: Access Route Parameters for your page via $stateParams.parameterName
    function ($scope, $stateParams) {

    $scope.User = {};
    $scope.login = function() {
    str="Dont know what to put here";
                $http.get(str)
                .success(function (response){  
          }).error(function() {                         //if login failed
                        var alertPopup = $ionicPopup.alert({
                            title: 'Login failed!',
                            template: 'Please check your credentials!'
                        });
                });
            };

    }])

login html 登录html

<ion-view title="Login" id="page6">
  <ion-content padding="true" class="has-header">
    <form id="login-form4" class="list">
      <ion-list id="login-list2">
        <label class="item item-input" id="login-input10">
          <span class="input-label">Username/Email</span>
          <input type="text" ng-model="User.email" placeholder="">
        </label>
        <label class="item item-input" id="login-input11">
          <span class="input-label">Password</span>
          <input type="password" ng-model="User.password" placeholder="">
        </label>
      </ion-list>
      <div class="spacer" style="height: 40px;"></div>
      <a id="login-button2" ng-click="login()" class="button button-positive  button-block">Log in</a>
      <a ui-sref="signup" id="login-button3" class="button button-positive  button-block button-clear">Or create an account</a>
    </form>
  </ion-content>
</ion-view>

Currently, the Azure App Service Mobile Apps SDK is provided for ASP.NET and Node.js web applications. 当前,为ASP.NET和Node.js Web应用程序提供了Azure App Service移动应用程序SDK。 So, you could switch your backend to Node.js or .NET backend instead. 因此,您可以将后端切换到Node.js或.NET后端。

Then you can create Easy API / Custom API in your mobile backend, and you are able to connect your API with invokeApi() of Javascript Clients for Azure Mobile Apps . 然后,您可以在移动后端中创建Easy API / Custom API ,并且可以将您的API与适用 于Azure移动应用Javascript客户端的 invokeApi()连接起来。

For more information, please refer to this blog post . 有关更多信息,请参阅此博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM