How to create a “loading screen” for a first spa visit SPA session

I created a one-page application using Hot Towel.

When I started, I had this "first boot screen" when it was caching. I deleted it, but I cannot figure out how to redefine it. I also added many other frameworks, and since then my webpage has become much more complicated. I still use RequireJS, Knockout and AngularJS in the first place.

I am not sure how to do this.

I do not remember how this was done initially, and I am having problems finding how to implement it.

Can anyone point me in the right direction?

+4
source share
3 answers

Maybe something like the following

<div class="loadingScreen" ng-show="!isLoaded">
  <div>Loading...</div>
</div>
<div class="container ng-hide" ng-show="isLoaded" >
   Page Content
</div>

Js

angular.module('myApp').controller("itemController", function($scope, itemService){
    $scope.isLoaded = false;
    ...Other stuff down here...

    //After your ajax call that saturates your view, set $scope.isLoaded = true;
    itemService.getItems().success(function(data){ 
       $scope.isLoaded = true;
    });
}

CSS

.loadingScreen{
   position: absolute;
   left: 0;
   right: 0;
   top: 0;
   bottom: 0;
   background-color: white;
   text-align: center;
   -webkit-transform-style: preserve-3d;
}

.loadingScreen > div{
  position: absolute;
  top: 47%;
  left: 47%;
}
+2
source

On the hot towel gitub page: https://github.com/johnpapa/HotTowel-Angular/blob/master/NuGet/HotTowel-NG/index.html

    <div id="splash-page" data-ng-show="false">
        <div class="page-splash">
            <div class="page-splash-message">
                Hot Towel Angular
            </div>
            <div class="progress progress-striped active page-progress-bar">
                <div class="bar"></div>
            </div>
        </div>
    </div>

c ng-show="false"is a secret sauce

+2
source

/ . (raw html), angular . , , appReady, splash ngIf.

<div class="body-content panel-body text-center" ng-if="!appReady">   
    <div class="row" >
      <div class="col-sm-12">
        <div class="">
          <i class="fa fa-spin fa-spinner fa-5x"></i>
         <h3>
         App is loading
         </h3> 
        </div>
      </div>
    </div>
    </div>

:

var app = angular.module('app', []);
  app.run(['$rootScope',initApp]);  

  //initializes the scope variables
  function initApp($rootScope){    
      $rootScope.appReady = true; 
      $rootScope.appMessage = 'App is ready';  
  }

ngCloak.

<div class="body-content" ng-cloak>
...
</div>

:

http://www.ozkary.com/2016/03/angularjs-splash-view-to-prevent-flicker-on-init.html

0
source

Source: https://habr.com/ru/post/1538228/


All Articles