离子项目,不是在手机上工作,而是在开发过程中工作


Ionic Project, Not working on phone but working during development

有一些我无法理解的东西。

正在学习一个离子框架并创建了一个简单的登录页面,我能够通过编辑器进行处理(我正在使用安装了离子实时预览的 Atom 编辑器)以及我可以登录或注册的浏览器,它会带我到下一页。

但真的很奇怪,当我将项目编译到.APK并安装在我的手机上。

伙计们有什么想法吗?

更新

也不能在安卓模拟器中运行它,但在使用 ionic 服务的浏览器中工作正常。

这是我的一些代码。

登录.html

<ion-header-bar align-title="center" class="bar-balanced">
  <h1 class="title">Login</h1>
</ion-header-bar>
<ion-view>
    <ion-content class="padding has-header">
      <ion-list>
        <ion-item>
          <input type="text" ng-model="login.username" placeholder="Username">
        </ion-item>
        <ion-item>
          <input type="password" ng-model="login.password" placeholder="Password">
        </ion-item>
      </ion-list>
      <button nav-clear class="button button-block button-balanced" ng-click="LogIn()">Login</button>
      <button class="button button-positive button-clear button-full" ui-sref="signup">Register now!</button>
    </ion-content>
</ion-view>

登录.php

<?php
    require_once 'dbConfig.php';
    // check username or password from database
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $user = $request->username;
    $password = $request->password;
    $results = mysql_query("SELECT email, password FROM tbl_user WHERE email='".$user."' AND password='".$password."' LIMIT 1") or die('{"error":"Login error! Code: 003"}');
    $match  = mysql_num_rows($results);
    if($match > 0 ){
      echo "1";
    }else{
      echo "0";
    }
?>

控制器.js

    angular.module('ionicApp.controllers', [])

.controller('AppCtrl', function($scope) {
})

.controller('LoginCtrl', function($scope, $state, $http, $ionicPopup) {
  $scope.showAlert = function(msg) {
      $ionicPopup.alert({
          title: msg.title,
          template: msg.message,
          okText: 'Ok',
          okType: 'button-positive'
      });
    };

  $scope.login = {};
  $scope.LogIn = function() {
    if(!$scope.login.username){
      $scope.showAlert({
        title: "Information",
        message: "Please enter your email address"
      });
    }else if(!$scope.login.password){
      $scope.showAlert({
        title: "Information",
        message: "Please enter your password"
      });
    }else{
      var request = $http({
          method: "post",
          url: "http://www.mywebsite.com/api/login.php",
          data: {
            username: $scope.login.username,
            password: $scope.login.password
          },
          headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        });
        /*Successful HTTP post request or not */
        request.success(function (data){
          if (data == '1'){
            $state.go('app.test');
            }
          else {
            var alertPopup = $ionicPopup.alert({
                  title: 'Login failed!',
                  template: 'Please check your credentials!'
            });
          }
        })
    }
  };
});

应用.js

angular.module('ionicApp', ['ionic','ionicApp.controllers'])
.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('app', {
      url: "/app",
      abstract: true,
      templateUrl: "templates/menu.html",
      controller: 'AppCtrl'
    })

    .state('app.test', {
      url: '/test',
      views: {
        'menuContent': {
          templateUrl: 'templates/test.html'
        }
      }
    })

    .state('login', {
      url: "/login",
      templateUrl: "templates/login.html",
      controller: 'LoginCtrl'
    });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/login');
});

发现,问题与科尔多瓦插件有关。

遇到此问题的任何人都可以尝试此修复程序。

只需运行科尔多瓦插件,在我们的项目文件夹中添加科尔多瓦插件白名单并重建它。