저는 모바일 개발 세계에 새로운 경험이 있으며 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');
})
};
모든 도움을 받으실 수 있습니다.
크롬 원격 디버거에서 확인 콘솔 –
답을 자세히 설명해 주시겠습니까? 브라우저에서 문제가 발생하지 않아 문제가있는 안드로이드 시뮬레이터입니다. – Baig
네, 그래서 당신이 당신의 안드로이드 장치를 실행하는 동안 당신이 콘솔을 확인 말하는거야. 안드로이드 장치를 노트북의 open chrome type'chrome : // inspect'에 연결하면 장치에서 실행중인 앱을 검사 할 수 있습니다. –