Create a simple login / $digest already in progress


#1

Hi.
I’m trying to interact w/ my backend using Ionic’s $http-object. Unfortunately, I don’t know how to transition from login / registration to my main app properly, since I’m always getting a “$digest already in progress”-error. Can anyone help me here?

Also, is there like a standardized way to store something like a session_id after a successful login?

Thanks!

.controller('loginCtrl', function($scope, $http, $rootScope, $ionicLoading, $state) {
        $scope.doLogin = function() {
            var email = $scope.loginData.email; 
            var password = $scope.loginData.password; 
            if (!email || !validateEmail(email) || !password) {
                alert('err missing login');
                return;
            } else {
                var requestData = {
                    email: email,
                    password: password
                };
                $ionicLoading.show({
                    template: 'Loading...'
                });
                $http.post("http://domain.com/rest/login", requestData, {
                    headers: {'Content-Type': 'application/json'}
                }).success(function(responseData) {
                    alert('Login successful!');
                        $state.transitionTo("/intro");
                }).error(function(err) {
                    if (err.error && err.error.length >= 1) {
                        alert(err.error[0].message);
                    }
                }).finally(function() {
                    $ionicLoading.hide();
                });
            }
        };
    })

#2

That error typically means you are manually doing a $scope.$digest() or $scope.$apply() somewhere in your code. Is that being done anywhere else in your application?