Delaying AngularJS route change until model loaded to prevent flicker

后端 未结 13 2328
误落风尘
误落风尘 2020-11-22 02:28

I am wondering if there is a way (similar to Gmail) for AngularJS to delay showing a new route until after each model and its data has been fetched using it

13条回答
  •  臣服心动
    2020-11-22 03:05

    I have had a complex multi-level sliding panel interface, with disabled screen layer. Creating directive on disable screen layer that would create click event to execute the state like

    $state.go('account.stream.social.view');
    

    were producing a flicking effect. history.back() instead of it worked ok, however its not always back in history in my case. SO what I find out is that if I simply create attribute href on my disable screen instead of state.go , worked like a charm.

    
    

    Directive 'back'

    app.directive('back', [ '$rootScope', function($rootScope) {
    
        return {
            restrict : 'A',
            link : function(scope, element, attrs) {
                element.attr('href', $rootScope.previousState.replace(/\./gi, '/'));
            }
        };
    
    } ]);
    

    app.js I just save previous state

    app.run(function($rootScope, $state) {      
    
        $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {         
    
            $rootScope.previousState = fromState.name;
            $rootScope.currentState = toState.name;
    
    
        });
    });
    

提交回复
热议问题