Bhautik129
Bhautik129

Reputation: 15

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;

    }); 
}   
});

Upvotes: 0

Views: 6076

Answers (4)

Wasiq Muhammad
Wasiq Muhammad

Reputation: 3128

Try this

 $location.path('/timetrake/welcome.html');

I prefer you to use ng-route it gives you more flexibility and it maintain state for redirection and it can easily navigate by just

$state.go()

Upvotes: 0

Lautaro Bertuzzi
Lautaro Bertuzzi

Reputation: 101

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;

    }); 

Upvotes: 2

byteC0de
byteC0de

Reputation: 5273

Inject $location in your controller

For example

jimApp.controller('mainCtrl', function($scope, $location){

    $location.url(".....")
});

Upvotes: 0

Giri
Giri

Reputation: 565

$location.path('/timetrake/welcome.html');

Why dont you add welcome.html into a scope route config and so u can do '/timetrake/welcome'

Upvotes: 0

Related Questions