Reputation:
I want to know how to redirect to another page using Angular Js.
I already follow several questions here and don't find any answer with works successfully
This is my code :
var app = angular.module('formExample',[]);
app.controller('formCtrl',function($scope,$http){
$scope.insertData=function(){
// if($scope.name =='' && $scope.email == '' && $scope.message = '' && $scope.price =='' && $scope.date == null && $scope.client == ''){return;}
$http.post("/php/login.php", {
"email": $scope.email, "password": $scope.password
}).then(function(response, $location){
alert("Login Successfully");
$scope.email = '';
$scope.password = '';
$location.path('/clients');
},function(error){
alert("Sorry! Data Couldn't be inserted!");
console.error(error);
});
}
});
I´m getting this error:
TypeError: Cannot read property 'path' of undefined
Upvotes: 3
Views: 146
Reputation: 126
You can use a plain JS
window.location.href = '/my-other-page'
Or, if you are using 'ui-router'
$state.reload()
or
$state.go($state.current.name, {}, {reload: true})
don't forget to inject $state into your controller dependencies:
app.controller('formCtrl',function($scope, $http, $state){
Upvotes: 0
Reputation:
You can redirect using $window in your controller.
$window.location.href = '/index.html';
Hope this helps you
Upvotes: -1
Reputation: 222522
You need to inject $location
to your controller,
app.controller('formCtrl',function($scope,$http,$location){
Upvotes: 3