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
Regular Expression to Accept Both Positive and Negative Numbers
Youtube API - Failed to Execute 'Postmessage' on 'Domwindow'
How to Toggle (Hide/Show) Sidebar Div Using Jquery
Size of Json Object (In Kbs/Mbs)
Get Image from Json File Using JavaScript and Display in HTML Img Tag
How to Prevent the Keyboard from Popping Up on Mobile Devices
Nodejs MySQL Get Correct Timestamp Format
Can We Cast a Generic Object to a Custom Object Type in JavaScript
React Js - How to Get Click Event Values from Child Component to Parent Component
How to Prevent a Key Input from Appearing in Input Field
How to Instantiate a File Object in JavaScript
How to Assign [(Ngmodel)] With an Empty/Null/Undefined Object - Angular 4
How to Combine First Name and Last Name in JavaScript
Chrome Blank Pdf Print Preview
Sticky Header Smoothing Scroll Down