2016-10-10 3 views
0

저는 모바일 개발 세계에 새로운 경험이 있으며 IonicFramework를 사용하여 손을 잡고 있습니다.이오닉 - 브라우저와 iOS 시뮬레이터에서는 잘 작동하지만 안드로이드 시뮬레이터에서는 작동하지 않습니다.

나는 로그인 양식을 만들고 있는데, 로그인에 성공하면 사용자는 viewMyList라고하는 다른 상태로 이동하게됩니다. 모든 명령을 실행할 때 잘 작동하는 것 같습니다. ionic serve 로그인 할 수 있고 다음 상태로 진행할 수 있습니다.하지만 iOS 시뮬레이터에서도 문제가 없지만 안드로이드 시뮬레이터에서 로그인 버튼을 클릭하지 않으면 아무 일도 일어나지 않습니다. 오류를 참조하십시오.

login.html

<ion-view title="Login"> 
    <ion-content class="has-header" padding="true"> 
     <form class="list"> 
      <h2 id="login-heading3" style="color:#000000;text-align:center;">Welcome back!</h2> 
      <div class="spacer" style="width: 300px; height: 32px;"></div> 
      <ion-list> 
       <label class="item item-input"> 
        <span class="input-label">Email</span> 
        <input type="text" placeholder="" ng-model="credentials.username"> 
       </label> 
       <label class="item item-input"> 
        <span class="input-label">Password</span> 
        <input type="text" placeholder="" ng-model="credentials.password"> 
       </label> 
      </ion-list> 
      <div class="spacer" style="width: 300px; height: 18px;"></div> 
      <a class="button button-positive button-block" ng-click="login()">Sign In</a> 
     </form> 
    </ion-content> 
</ion-view> 

ng-click가 여기에 login()

와 연결되어 내 시도는 login() 기능이 포함되어 내 loginCtrl입니다

.controller('loginCtrl', function ($scope, $state, $ionicHistory, User) { 

    $scope.credentials = { 
     username: '', 
     password: '' 
    }; 
    $scope.login = function() { 
     User.login($scope.credentials) 
      .then(function (response) { 
       console.log(JSON.stringify(response)); 
       //Login should not keep any history 
       $ionicHistory.nextViewOptions({historyRoot: true}); 
       $state.go('app.viewMyList'); 
      }) 
    }; 

    $scope.message = "this is a message loginCtrl"; 
}) 
,

다음은 로그인

.state('login', { 
     url: '/login', 
     templateUrl: 'templates/login.html', 
     controller: 'loginCtrl' 


    }) 

내가 알아낼 어차피 같은 순간에 정말 우둔 오전 뒤에 route입니다 로그인 로직 여기

angular.module('app.user', []) 
    .factory('User', function ($http) { 

     var apiUrl = 'http://127.0.0.1:8000/api'; 
     var loggedIn = false; 

     return { 
     login: function (credentials) { 
      console.log(JSON.stringify('inside login function')); 
      console.log(JSON.stringify(credentials)); 
      return $http.post(apiUrl + '/tokens', credentials) 
       .success(function (response) { 
        console.log(JSON.stringify('inside .then of login function')); 
        var token = response.data.token; 
        console.log(JSON.stringify(token)); 
        $http.defaults.headers.common.Authorization = 'Bearer ' + token; 
        persist(token); 
       }) 

       .error(function (response) { 
        console.log('inside error of login function'); 
        console.log(JSON.stringify(response)); 
       }) 
       ; 
     }, 

      isLoggedIn: function() { 
       if (localStorage.getItem("token") != null) { 
        return loggedIn = true; 
       } 
      } 
     }; 

     function persist(token) { 

      window.localStorage['token'] = angular.toJson(token); 
     } 
    }); 

을 담당 내 User 서비스 안드로이드에서 아무 일도 일어나지 않는 이유는, 로그인 버튼을 클릭했을 때 코드가 다음과 같은 기능을 수행하지 않는 것 같았습니다.

$scope.login = function() { 
    User.login($scope.credentials) 
     .then(function (response) { 
      console.log(JSON.stringify(response)); 
      //Login should not keep any history 
      $ionicHistory.nextViewOptions({historyRoot: true}); 
      $state.go('app.viewMyList'); 
     }) 
}; 

모든 도움을 받으실 수 있습니다.

+0

크롬 원격 디버거에서 확인 콘솔 –

+0

답을 자세히 설명해 주시겠습니까? 브라우저에서 문제가 발생하지 않아 문제가있는 안드로이드 시뮬레이터입니다. – Baig

+0

네, 그래서 당신이 당신의 안드로이드 장치를 실행하는 동안 당신이 콘솔을 확인 말하는거야. 안드로이드 장치를 노트북의 open chrome type'chrome : // inspect'에 연결하면 장치에서 실행중인 앱을 검사 할 수 있습니다. –

답변

0

먼저 화이트리스트 플러그인을 설치하십시오. 프로젝트의 루트 디렉토리

<allow-navigation href="http://example.com/*" /> 

또는 아래에 당신의 config.xml에 파일의 코드를 다음

cordova plugin add cordova-plugin-whitelist 

추가 :

<allow-navigation href="http://*/*" /> 

당신이 어떤 문제에 직면하고 여전히 경우에, 당신은 안드로이드 장치에서 실행 중일 때 콘솔을 확인할 수 있습니다. chrome remote debugging

  • 기기를 기기와 연결합니다 (휴대 기기에서 USB 디버깅을 사용하도록 설정해야 함).

  • chrome://inspect을 (를) 데스크톱 크롬으로 사용하십시오.

  • 연결된 장치가 표시되고 검사를 선택하고 로그 콘솔을 확인하십시오.

+0

'플러그인 'cordova-plugin-whitelist가 이미 Android에 설치되었습니다.'cordova-plugin-whitelist를 추가하려고 할 때 콘솔에 표시되는 내용이고'allow-navigation'도 도움이되지 않습니다. – Baig

+0

당신은 당신이 설치 한 whitelist를 설치하기 전에 no –

+0

라고 말합니다. 모바일 개발 세계에 정말 새로운 것이므로, 모든 cordova 플러그인이 이온으로 사전 설치된 것을 알지 못했습니다. – Baig

관련 문제