Prevent a stateChange with angular ui router without using $rootScope

后端 未结 3 587
独厮守ぢ
独厮守ぢ 2021-01-31 08:55

My user can leave a state but before I want to show a modal dialog \"Do you want to save?\"

ONLY if the user data is dirty that means changed.

What I do NOT wan

3条回答
  •  没有蜡笔的小新
    2021-01-31 09:19

    Using $transitions.onStart (angular-ui-router 1.0.0-rc) you can return a boolean. If false the transition will be cancelled.

    $transitions.onStart({}, function (trans) { 
        var answer = confirm("Want to leave this page?")
        if (!answer) {
            return false;
        }
    });
    

    Here is the documentation: https://ui-router.github.io/ng1/docs/latest/modules/transition.html#hookresult

提交回复
热议问题