0

I have a login form and I am simply trying to change the path once the register button is selected. For some reason the login button works but the register button does not. When I click it nothing happens. Even if I put an alert inside the register controller nothing comes up which tells me that the controller function is not being executed. I am new to angular js and not sure if I understand ng-click and $location.path well

here is my code for the register button:

<button ng-click="register()" class="btn btn-default" id="lefty" >Register</button> 

and my code for the controller and the route provider in app.js:

$routeProvider.when('/register', {
        templateUrl: 'app/partials/register.html',
        controller: 'RegisterController'

      });



app.controller('RegisterController', function($scope, $location) {
        $scope.register = function() {
        $location.path('/register');
    }
});

I simply expect once register button is clicked to be able to go to the /register path.

2 Answers 2

1

I think you have the Register button on the login page. As per your code register method is inside RegisterController so it is not available on the Login page. Move this method to your login page controller it should work fine.

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

Comments

0

You need to use $window:

    app.controller('RegisterController', function($scope, $window) {
    $scope.register = function() {
    $window.location = '#/register';
}
});

1 Comment

The $location object doesn't change effective the current path. It only prepare or capture data for any url

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.