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;
});
}
});
Asked
Active
Viewed 5,972 times
0

Abhishek Gurjar
- 7,426
- 10
- 37
- 45

Bhautik129
- 15
- 1
- 5
-
it give error like this Reference Error: $location is not defined at my Succes – Bhautik129 May 04 '16 at 05:05
-
$location needs to be passed as argument in the controller function such as .controller("LocationController", function($scope, $location) { – Giri May 04 '16 at 05:06
-
what happen when you try to redirect? – uzaif May 04 '16 at 05:08
-
i passed the argument in the controller but it doesn't work – Bhautik129 May 04 '16 at 05:13
-
thank you guys it's working – Bhautik129 May 04 '16 at 05:23
-
@Bhautik129 Don't forget to Mark one of the answers correct. – Giri May 04 '16 at 05:24
4 Answers
2
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;
});

Lautaro Bertuzzi
- 101
- 5
0
$location.path('/timetrake/welcome.html');
Why dont you add welcome.html into a scope route config and so u can do '/timetrake/welcome'

Giri
- 565
- 2
- 9
0
Inject $location
in your controller
For example
jimApp.controller('mainCtrl', function($scope, $location){
$location.url(".....")
});

byteC0de
- 5,153
- 5
- 33
- 66
0
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()

Wasiq Muhammad
- 3,080
- 3
- 16
- 29