user8472773
user8472773

Reputation:

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

Upvotes: 3

Views: 146

Answers (3)

Maxwellt
Maxwellt

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

user8482185
user8482185

Reputation:

You can redirect using $window in your controller.

$window.location.href = '/index.html';

Hope this helps you

Upvotes: -1

Sajeetharan
Sajeetharan

Reputation: 222522

You need to inject $location to your controller,

app.controller('formCtrl',function($scope,$http,$location){    

Upvotes: 3

Related Questions