$ location.path在$ locationChangeStart回调中没有导航属性

时间:2014-09-22 16:09:25

标签: angularjs url-routing

为了防止对包含编辑的表单进行视图更改,我使用$ locationChangeStart来拦截视图更改。在该函数中,我试图使用引导程序对话框来提示用户。

一切正常,直到我调用$ location.path(current)来更改视图的部分。它将转到默认路径(主页),而不是导航到适当的路径。这是为什么?

以下是我在控制器中使用的代码:

function onNavigate() {
var turnOff = $scope.$on('$locationChangeStart',
    function (event, current, previous) {
        if (vm.canSave) {
            dialogService.confirmationDialog('Are you sure?', 'You have unsaved changes, are you sure you want to abandon your form?')
                .then(function() {
                    turnOff();
                    $location.path(current);
                });
            event.preventDefault();
        });
}

在调试器中,current的值类似于

http://localhost:3091/#/participant/24 

在$ location.path行,但我的应用程序最终在

http://localhost:3091/#/

0 个答案:

没有答案