Bhautik129 Bhautik129 - 6 months ago 25
HTML Question

How to redirect a page in angularjs

angular.module('myApp',[])

.controller('loginCtrl',function ($scope, $http, $rootScope, $location, $window{
$scope.login = function(loginData){

$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);
$location.url('http://localhost/timetrake/welcome.html');

}, function myError(response) {

$scope.user = response.statusText;

});


}

});

Answer

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;

    }); 
Comments