Lara
Lara

Reputation: 3021

Page is not redirecting in Angular JS

I have a button in which i have registered a click event . Now as per my requirement i want my current page to route to next page using Angular JS routing .I am trying to add routing code in my click event but its not happening. Here is my Angular JS code..

 var app = angular.module('LoginApp', ['ngRoute']);
 app.config(function ($routeProvider) {
 app.controller('LoginformController', function ($scope) {

        $scope.LoginCheck=function () {

         alert("Trying to login !");

        }
 });

Now after alert i want this page to navigate to 'Home.html'.Please help me how to route to 'Home.html' after alert message.Thanks

I am trying to add below code but the page is not navigating ..

app.config(function ($routeProvider) {

app.controller('LoginformController', function ($scope,$location) {

    $scope.LoginCheck=function () {

    alert("Trying to login !");

    $location.path('/Home.html');

}

$scope.PasswordRecovery = function () {
    alert("Clicked 2");
}
});
});

Upvotes: 0

Views: 1279

Answers (2)

intekhab
intekhab

Reputation: 1596

try this

var app = angular.module('LoginApp', ['ngRoute']);
 app.config(function ($routeProvider) {
 app.controller('LoginformController', ['$scope', '$location', function ($scope, $location) {

        $scope.LoginCheck=function () {

         alert("Trying to login !");
         $location.path('path where to redirect');
        }
 }]);

$location.path is getter and setter both It will get when without parameter ie $location.path(); And it will set when with parameter ie $location.path('path to redirect')

Upvotes: 3

Rafael K
Rafael K

Reputation: 16

Try this:

var app = angular.module('LoginApp', ['ngRoute']);

app.config(['$routeProvider',function ($routeProvider) {

   $routeProvider


        .when('/Login', {
            templateUrl: 'LoginView.html',
            controller: 'LoginController'
        })
}])

app.controller('LoginformController', function($scope,$location) {

  $scope.LoginCheck = function(){
     alert("Trying to login !");
     $location.path('/Login');
  }
});

Upvotes: 0

Related Questions