Alert popup have errors

I’m having issue with $ionicPopup. It gives me error
ionic.bundle.js:26799 TypeError: Cannot read property ‘alert’ of undefined
at controllers.js:44
at processQueue (ionic.bundle.js:29132)
at ionic.bundle.js:29148
at Scope.$eval (ionic.bundle.js:30400)
at Scope.$digest (ionic.bundle.js:30216)
at Scope.$apply (ionic.bundle.js:30508)
at done (ionic.bundle.js:24829)
at completeRequest (ionic.bundle.js:25027)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:24968)

this is my code
.controller(‘loginCtrl’, [’$scope’, ‘ionicToast’, ‘AuthService’, function($scope, $stateParams, AuthService,$location, $rootScope,$state,$ionicLoading, $ionicPopup) {

$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();
$state.go(‘app.dashboard’);
},function(errMsg) {
var alertPopup = $ionicPopup.alert({
title: ‘Invalid Email / Password’,
template: errMsg
});
});
//.finally(function() {
// $ionicLoading.hide();
//});
};

};
}])

before this it gave me .show is not defined and then this problem. How to solve it?

Hi!

The problem is in your controller function. When you use the brackets notation, all your brackets parameters must be the same that your last function parameter

Example:

.controller(["a", "b", "c", "d", function(a, b, c, d){}])

You can not do this:

.controller(["a", "b", "c", "d", function(a, b){}])

because c and d would be undefined.

Your solution is change your controller function to:

.controller('loginCtrl', ['$scope', 'stateParams', 'AuthService', '$location', '$rootScope', '$state', '$ionicLoading', '$ionicPopup', 
function($scope, $stateParams, AuthService,$location, $rootScope,$state,$ionicLoading, $ionicPopup)

That should work.

It works now. Thank you!

1 Like