Javascript $location.path()不适用于角度布线

Javascript $location.path()不适用于角度布线,javascript,angularjs,Javascript,Angularjs,我知道关于这个问题这里有几个帖子。我在这一点上已经尝试了所有这些,这可能就是为什么代码在这一点上看起来很糟糕。我想做的事情看起来很简单。在提交表单时,我想通过Angular的路由重定向到另一个视图 这是从表单提交函数调用的 $http.post('/api/brackets', jsonData, { headers: headers }) .success(function(data, status, headers, config) { $scope.brackets = da

我知道关于这个问题这里有几个帖子。我在这一点上已经尝试了所有这些,这可能就是为什么代码在这一点上看起来很糟糕。我想做的事情看起来很简单。在提交表单时,我想通过Angular的路由重定向到另一个视图

这是从表单提交函数调用的

$http.post('/api/brackets', jsonData, { headers: headers })

   .success(function(data, status, headers, config) {
   $scope.brackets = data;
   $scope.$on('$routeChangeStart', function(next, current) { 
       $console.log('$routeChangeStart', arguments);
      });
   $location.path('/leaderboard').replace(); ///this is where I am trying to redirecto    to
 $scope.apply().replace();
 $location.path('');                        
})
**这在路由提供商**

angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider',       function($routeProvider, $locationProvider) {

 // Enable pushState in routes.
$locationProvider.html5Mode(true).hashPrefix('!');
$routeProvider

    // home page
    .when('/', {
        templateUrl: 'views/signin.html',
        controller: 'authController'
    })
    .when('/signin', {
        templateUrl: 'views/signin.html',
        controller: 'authController'
    })
    .when('/signup', {
        templateUrl: 'views/signup.html',
        controller: 'authController'
    })

    .when('/dash', {
        templateUrl: 'views/dashboard.html',
        controller: 'dashController'
    })
    .when('/test', {
        templateUrl: 'views/test.html',
        controller: IndexCtrl
    })
    .when('/profile', {
        templateUrl: 'views/profile.ejs',
        controller: IndexCtrl
    })
    .when('/leaderboard', {
        templateUrl: 'views/leaderboard.html',
        controller: 'leaderboardController' // we might want to make this a partial
    })
    .otherwise({
        redirectTo: '/'
    });

//$locationProvider.html5Mode(true);

}]);
任何帮助都将不胜感激。谢谢

$http.post('/api/brackets', jsonData, { headers: headers })
.success(function(data, status, headers, config) {
    $scope.brackets = data;
    $scope.$on('$routeChangeStart', function(next, current) { 
        $console.log('$routeChangeStart', arguments);
    });
    $location.path('/leaderboard').replace(); ///this is where I am trying to redirecto    to
    $scope.apply().replace();
    $location.path('');                        
})
我觉得这很不对劲,首先你告诉$location.path去/排行榜,但两行之后你告诉它去哪儿都不去。你是否打算这样做:

$http.post('/api/brackets', jsonData, { headers: headers })
.success(function(data, status, headers, config) {
    $scope.brackets = data;
    $scope.$on('$routeChangeStart', function(next, current) { 
        $console.log('$routeChangeStart', arguments);
    });
    $location.path('/leaderboard');              
})

你为什么要申请美元?还有,为什么要执行.replace?

您的.apply()应该是.apply()位置.path(“”);这是一个打字错误。这不在我的代码中。我做了申请和替换,因为这里的其他帖子也有同样的问题,这很有效。但是这对我不起作用。关于你理解上面代码的问题…再次根据另一篇帖子,有人说这将是一种通过控制台检查路线更改是否正在注册的方法。你必须更具体地说明你的代码是什么,无论出于何种目的,它都应该工作。http post被包装在一个onSubmit函数中,用于将json文档插入mongoDB的表单,然后应该重定向到/Leadboard,这是列出的路由之一。这是行不通的。还有什么其他细节会指出可能的问题?谢谢