How to Redirect to Another Page Using Angularjs

How to redirect to another page using AngularJS?

You can use Angular $window:

$window.location.href = '/index.html';

Example usage in a contoller:

(function () {
'use strict';

angular
.module('app')
.controller('LoginCtrl', LoginCtrl);

LoginCtrl.$inject = ['$window', 'loginSrv', 'notify'];

function LoginCtrl($window, loginSrv, notify) {
/* jshint validthis:true */
var vm = this;
vm.validateUser = function () {
loginSrv.validateLogin(vm.username, vm.password).then(function (data) {
if (data.isValidUser) {
$window.location.href = '/index.html';
}
else
alert('Login incorrect');
});
}
}
})();

How to redirect a page in angularjs

You can use Angular $window:

$window.location.href = 'timetrake/welcome.html';

Then

 $scope.dataLoading = true;
$scope.loginData = angular.copy(loginData);
$http({
method : 'GET',
url : 'php/login.php',
params: {'email' : loginData.email,'password': loginData.password,'rand' : Math.random()}
}).then(function mySucces(response,$location){
$scope.dataLoading = false;
$scope.msg1 = response.data.msg1;
$scope.msg2 = response.data.msg2;
$scope.firstname = response.data.firstname;
$scope.flag = response.data.flag;
console.log($scope.flag);
$window.location.href = 'timetrake/welcome.html';);

}, function myError(response) {

$scope.user = response.statusText;

});

How to redirect a page to another using AngularJS in ExpressJS

You have a problem in dependency injection (first controller):

myapp.controller('loginctrl', ['$scope', '$route', '$routeParams', '$location', 
function($scope, $http, $location) {

You didn't inject the same things. Change it to:

myapp.controller('loginctrl', ['$scope', '$route', '$http', '$routeParams', '$location', 
function($scope, $route, $http, $routeParams, $location) {

How to redirect to other page after successful login in angularjs?

Try this,

 $window.location.href = '/Home/index.html';

also inject $window to your controller

app.controller('Login', function ($scope, LoginService,$window) {
$scope.Login = function () {
var sub = {
User_Name: $scope.User_Name,
User_Password: $scope.User_Password
};
var checkData = LoginService.Login(sub);
checkData.then(function (data) {
//want redirection
$window.location.href = '/Home/index.html';
}, function (error) {
})
};
});

redirecting to another page using angularjs on button click

You should use the angular route system or ui.router :

ngRoute and location

$location.path( "#/join" );

ui.router

$state.go(path_to_join_state);


Related Topics



Leave a reply



Submit