Opposite of ng-cloak for loading message

All we need is an easy explanation of the problem, so here it is.

I don’t know if this exists in the AngularJS framework, but essentially I’m looking for the opposite of ng-cloak, which hides elements until the page is compiled. I was looking for a way to show a full screen loading message until the page is compiled. Is there something built into the language to handle this?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I have resolved this using a somewhat hacky method as follows. The following HTML is added at the end of the main page.

<div ng-show="::false" style="position: fixed; height: 100%; width: 100%; background-color: #353535; top: 0; left: 0; z-index: 10000;">
    <div style="display: table; margin: 0 auto; font-size: 26px; color: #CCC;">
        Loading
    </div>
</div>

The message is shown across the entire browser until the page is compiled, at which point ng-show takes over and hides the loading message.

EDIT:
Angular 1.3+ lets you use the :: expression to prevent evaluating the expression in every digest cycle.
https://docs.angularjs.org/guide/expression#one-time-binding

Method 2

<div ng-show>Loading Results...</div>

ng-show with no attribute specified compiles to false

Method 3

You can use css to archive this behavior.

Create a class:

.splash {
  display: none;
}

[ng-cloak].splash {
  display: block !important;
}

And then add:

<div class="splash" ng-cloak> Loading... </div>

This will show before the Angular code loads, and will hide after the angular code completes. Don’t forget to wrap your angular code with ng-cloak too.

<div ng-cloak> Your code... </div>

Method 4

This helped me:

https://codepen.io/garethdweaver/pen/PqKLyB

It can be used without &:after, but the idea is well shown here, and my decision based on this was as follows:

  .cloak-loader
    display: none !important

  [ng-cloak].cloak-loader
    position: relative
    display: block !important
    .loader
      height: 50px
      display: flex
      justify-content: center
      align-items: center

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply