1

Is there a way in angular that when I want switch to another state (ui-sref) that i can show some load icon until the second state is loaded?

1 Answer 1

4

yes angular ui.router has events which you can listen:

$stateChangeStart - fired when the transition begins.

$stateChangeSuccess - fired once the state transition is complete.

following this you can write preloader functionality

$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
   $rootScope.preloader = false;
}

  $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
       $rootScope.preloader = true;
    }

and write some <div> in your body element and show/hide it with this variable

eg.

<body> 
    <div ng-show="preloader"></div>
</body>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.