Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Angular Js重定向页面?_Javascript_Angularjs - Fatal编程技术网

Javascript 如何使用Angular Js重定向页面?

Javascript 如何使用Angular Js重定向页面?,javascript,angularjs,Javascript,Angularjs,我想知道如何使用Angular Js重定向到另一个页面 我在这里已经回答了几个问题,没有找到任何关于works的答案 这是我的代码: var app = angular.module('formExample',[]); app.controller('formCtrl',function($scope,$http){ $scope.insertData=function(){ // if($scope.name =='' && $sc

我想知道如何使用Angular Js重定向到另一个页面

我在这里已经回答了几个问题,没有找到任何关于works的答案

这是我的代码:

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);

            });
        }
    });
我得到这个错误:

TypeError: Cannot read property 'path' of undefined

您需要将
$location
注入控制器

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

您可以在控制器中使用$window重定向

$window.location.href = '/index.html';
希望这对您有所帮助

您可以使用普通的JS

window.location.href = '/my-other-page'
或者,如果您正在使用“ui路由器”

$state.reload()

不要忘记将$state注入控制器依赖项:

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

您需要在控制器中插入
$location
。详细答案已在控制器中的stackoverflowInject$location中提供,请不要忘记将其从成功回调函数中删除。错误:$injector:unpr未知提供程序未知提供程序:$urlProvider
$window.location.href
应仅用于完整设置页面重新加载。错误:$injector:unpr未知提供程序未知提供程序:$urlProvider我看不到任何地方urlProviderWell不工作,因为路径未定义@SajeetharanWhat?我不明白it@Maxwelt未知提供程序:$urlProvider将“$state”注入控制器的dependenciesapp.controller('formCtrl',函数($scope,$http,$state){
app.controller('formCtrl',function($scope, $http, $state){