stop angular-ui-router navigation until promise is resolved

前端 未结 10 1943
情歌与酒
情歌与酒 2020-12-01 02:44

I want to prevent some flickering that happens when rails devise timeout occurs, but angular doesn\'t know until the next authorization error from a resource.

What h

10条回答
  •  清歌不尽
    2020-12-01 03:34

    as $urlRouter.sync() doesn't work with stateChangeStart, here's an alternative:

        var bypass;
        $rootScope.$on('$stateChangeStart', function(event,toState,toParams) {
            if (bypass) return;
            event.preventDefault(); // Halt state change from even starting
            var meetsRequirement = ... // Perform custom logic
            if (meetsRequirement) {  // Continue with the update and state transition if logic allows
                bypass = true;  // bypass next call
                $state.go(toState, toParams); // Continue with the initial state change
            }
        });
    

提交回复
热议问题