nrvarun
nrvarun

Reputation: 193

Page redirection not working in angularjs using window.location.href

I am coding a page where after the user has entered the data in input fields, the data will be validated with an ajax request. After the data has been validated the page must be redirected to another page.

The below code is not working :

                $scope.validateUser = function() {

                    username = $scope.username;
                    password = $scope.password;

                    if ( username === "nrvarun89") {
                        console.log(username+" "+password+" path is :"+window.location.href);
                        window.location.href = "http://localhost/b2c-webadmin/index/";
                        console.log(username+" "+password+" new path is :"+window.location);
                    }
                };

Upvotes: 0

Views: 1385

Answers (1)

user4433120
user4433120

Reputation:

If you are using anuglarjs make use of the $window service (best practice):

https://docs.angularjs.org/api/ng/service/$window

This should work:

$window.location.href

(See this for reference: https://docs.angularjs.org/guide/$location)

Upvotes: 2

Related Questions