Lara
Lara

Reputation: 3021

Redirect to another web page

I am trying to redirect a WebPage into another .HTML page on button click using $location.path('/Views/Home.html'); but its not happening . The URL is getting changed into the browser but the page is not redirecting..Here is my AngularJS code..

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

$scope.LoginCheck = function () {

alert("Trying to login !");

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

}

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

I am getting both the alert functions but not getting the page redirection.Please help..

Upvotes: 1

Views: 103

Answers (2)

FrankCamara
FrankCamara

Reputation: 348

Correct me if I'm wrong but if you set the location object with a string, then it will set the default property href to that string. That's why you can set the location directly. What if object default property is changed in the future then

window.location = "http://example.com" 

will break.

Try this instead to be safe:

window.location.href = "http://example.com"

Upvotes: 0

Tushar
Tushar

Reputation: 616

If you are working with AngularJS then your above approach is wrong, you need to do it following way,

First create a routes for "Home"

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

  $routeProvider.when('/home', {
    templateUrl: 'your respective path/view/home.html',
    controller: 'homeCtrl'
  });

}]); 

Then use $location.path as follow,

$location.path("/home");

Upvotes: 2

Related Questions