IONIC APP-获取邮政服务的设备ID($ http.post)

时间:2016-11-14 09:13:10

标签: angularjs ionic-framework angularjs-scope angular-ui-router

我试图在app登录时获取设备ID getUUID以及用户名和密码。是获取设备ID并将其发布到服务器以进行登录的正确方法。

controller.js

      .controller('LoginCtrl', function($scope, $http,$rootScope,$window,$location,$cordovaDevice) {
         $scope.login = function () {
                var data ={

                  username : $scope.username,
                  password : $scope.password
                };
        document.addEventListener("deviceready", onDeviceReady, false);
            function onDeviceReady() {
               $http.post('login', data, config)
              .success(function (data, status, headers, config) {
                  // $scope.DataResponse = data;
                  $location.path('#/tab/new-order');
              })
              .error(function (data, status, header, config) {
                  $window.alert("username or password incorrect");
              });
                  console.log(device.cordova);
               }

        var config = {
            headers : {
                'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
            }
        }
    };

  })

html代码

  <form action="" class="ki-login-form" method="post" accept-charset="utf-8">
            <div class="form-group username">
                <input type="text" class="form-control" name="username" value="" id="identity" placeholder="Your Name">
            </div>
            <div class="form-group pin">
                <input type="text" class="form-control" name="password" value="" id="identity" placeholder="Your Pin">
            </div>
            <a type="submit" class="btns" ng-click='login()' >Login</a>
    </form>

登录后,必须将其定向到页面href =&#34;#/ tab / new-order&#34;在离子标签中

2 个答案:

答案 0 :(得分:1)

在控制器函数中添加依赖注入$ location,如下所示 -

 .controller('LoginCtrl', function($scope, $http, $rootScope,$window,$location) {
// Your code
});

添加评论的解决方案 -

使用以下 - 添加设备插件:cordova plugin add org.apache.cordova.device

在您的控制器中:

module.controller('MyCtrl', function($scope, $cordovaDevice) { 
    var uuid = $cordovaDevice.getUUID(); 
});

答案 1 :(得分:0)

更改此

var data = $.param({

              username : $scope.username,
              password : $scope.password,


   });

var data = {

              username : $scope.username,
              password : $scope.password,


   };

更新 -

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(device.cordova);
}