$scope.userLogin = function() {
//if($scope.user.data.email !== “” && $scope.user.data.password !== “” ){
//$ionicLoading.show ();
AuthService.login($scope.user.data).then(function(msg) {
//$rootScope.AuthCheck = AuthService.isAutheticate();
console.log(“here”);
$state.go(‘menu.dashboard’);
}, function(errMsg) {
console.log(“why here”);
ionicToast
.show(‘Invalid email / Password’, ‘center’, true, 2500);
// .then(function(success) {
// // success
// }, function (error) {
// // error
// });
})
//.finally(function() {
// $ionicLoading.hide();
//});
}
}])
Why when I login it will go to function(errMsg) and show the ionic toast?? It didnt go console log(“here”), it goes to console.log(“why here”). Anyone can help?
Adonai
March 31, 2017, 8:59am
2
That is because the AuthService.login
promise was rejected so it calls the second function (in your case, the errMsg).
The reason it was reject is impossible to know by us, because we do not have access to your code … but maybe you tried to login with the wrong credentials? What errMsg says?
it says “undefined”. I already put the correct username and password.
This is the longer code
.controller(‘loginCtrl’, [’$scope’, ‘$stateParams’, ‘AuthService’, ‘$location’, ‘$rootScope’, ‘$state’, ‘$ionicLoading’, ‘ionicToast’, function($scope, $stateParams, AuthService,$location, $rootScope,$state,$ionicLoading, ionicToast) {
$scope.user = {
data : {
email: “”,
password: “”
}
};
$scope.userLogin = function() {
//if($scope.user.data.email !== “” && $scope.user.data.password !== “” ){
//$ionicLoading.show ();
AuthService.login($scope.user.data).then(function(msg) {
//$rootScope.AuthCheck = AuthService.isAutheticate();
console.log(“sini”);
$state.go(‘menu.dashboard’);
}, function(errMsg) {
console.log(errMsg);
ionicToast
.show(‘Invalid email / Password’, ‘center’, true, 2500);
// .then(function(success) {
// // success
// }, function (error) {
// // error
// });
})
//.finally(function() {
// $ionicLoading.hide();
//});
}
}])
Adonai
March 31, 2017, 9:09am
4
Can you post the code of the login()
function of the AuthService
(without any sensible data of course)?
Also check that $scope.user.data
have the correct data
Ex:
$scope.userLogin = function() {
console.log($scope.user.data);
}