javascript - How to redirect Page using Angular Js? -


i want know how redirect page using angular js.

i follow several questions here , don't find answer works successfully

this 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 inserted!");                 console.error(error);              });         }     }); 

i´m getting error:

typeerror: cannot read property 'path' of undefined 

you can use plain js

window.location.href = '/my-other-page' 

or, if using 'ui-router'

$state.reload() 

or

$state.go($state.current.name, {}, {reload: true}) 

don't forget inject $state controller dependencies:

app.controller('formctrl',function($scope, $http, $state){  

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -