0

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);
                    }
                };
4
  • Do state why the code is not working, otherwise it's much harder to help you. Commented Oct 23, 2015 at 10:58
  • @Claies the page is not getting redirected Commented Oct 23, 2015 at 10:59
  • this code doesn't make sense. where is the call to this $scope.validateUser coming from? where is $scope.username and $scope.password being set? why are you taking in a parameter and then overwriting it's value as the first statement in the function? does the if block ever actually execute? Commented Oct 23, 2015 at 11:03
  • @Claies the if block does get executed i have tried checking it with a window.alert() Commented Oct 23, 2015 at 11:05

1 Answer 1

2

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)

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.