angularJS$location.url将url添加到当前url的末尾

angularJS$location.url将url添加到当前url的末尾,angularjs,Angularjs,已解决 诀窍是使用window.location='..' 我是AngularJS新手,在保存表单数据后遇到重定向问题 当我单击“保存”按钮时,我将数据发送到服务器,服务器将数据保存到数据库中 $scope.save = function (trips) { if (trips.length != 0) { tripsRepositorySave.save(trips).then(function () { $location.url('/Trip

已解决
诀窍是使用window.location='..'

我是AngularJS新手,在保存表单数据后遇到重定向问题

当我单击“保存”按钮时,我将数据发送到服务器,服务器将数据保存到数据库中

$scope.save = function (trips) {
    if (trips.length != 0) {
        tripsRepositorySave.save(trips).then(function () {
            $location.url('/Trips?id=' + trips[0].id);
        });
    }
};
这是tripsRepositorySave

app.factory('tripsRepositorySave', function ($http, $q) {
return {
    save: function (trips) {
        var deferred = $q.defer();
        $http.post('/Trips/Save', trips).success(function () { deferred.resolve(); });
        return deferred.promise;
    }
}
})
结果就是这个url

http://localhost:3333/Trips?assignmentID=2#/Trips?assignmentID=2
我无法让它重写整个路径,我尝试了$location.path、$scope.apply()和所有我能搜索到的东西,但结果还是一样

另一件事是,我想重新加载页面,但它似乎没有发生


谢谢你的建议:)

你想要这样的东西:

$location.path("/Trips").search('id', trips[0].id);
如果需要附加哈希,还可以查看哈希函数


$location

除了Andy Gaskell的答案

$location.url(…)将只管理“#”之后的部分。因此,您的代码按预期工作。
如果要重新加载整页,请使用或

谢谢!这就完成了:)我正试图摆脱散列,只是重写整个路径并重新加载:)window.location成功:)是的
window.location应该从你的angular应用程序中脱离出来,如果你想这么做的话。好吧,在我保存/添加所有项目后,我想重新加载页面,以便它使用ID等再次加载所有数据。也许我的整个方法是错误的。。?到目前为止,我只需要在一个页面上使用angular,所以我没有设置任何路由或任何东西。如果这对你有用,那就太棒了,但一般来说,这不是angular做事的方式。祝你好运