0

I have server side code which sends a response back (expressjs) to state if the user is authenticated or not.

I use $http post request and get the success back if all is ok. If user is authenticated I need to redirect the user to the relevant page.

My code here currently does not work or throw an error either when using debugging tools

$http({ method: 'POST',
            url: '/login',
            data: JSON.stringify({'username' : $scope.user.username, 'password' : $scope.user.password }),
            headers: {'Content-Type': 'application/json'}}).
            success(function (data, status, headers, config) {
                    $scope.invalid = false;
                   $window.location.href = '#/admin/';
                                   }).
            error(function (data, status, headers, config) {
                console.log(status);
                $scope.list = data;
            });

            return;
        };

Any help would be great.

1
  • Looks like you've got a period after the function instead of a semi-colon. Commented Jan 13, 2014 at 22:04

1 Answer 1

2

You can use $location to redirect

$location.path( "#/admin/" );

I would have expected your $window.location to also perform the redirect, so there could be something else going on. Do you have a route for '#/admin/' set up in a routeProvider? If not the default route would execute, if specified.

Sign up to request clarification or add additional context in comments.

1 Comment

hi i have the routeprovider setup .when('#/admin/', { templateUrl: 'views/admin/users.html', controller: 'UsersCtrl' })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.