Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect Page using Angular Js?

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

1 Answers

You need to inject $location to your controller,

app.controller('formCtrl',function($scope,$http,$location){    
like image 113
Sajeetharan Avatar answered Jun 30 '26 23:06

Sajeetharan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!