angularjsng-show

How to prevent element show before AngularJS initialized( ng-show )


In AngularJS, I wonder how to prevent the elements shown on page before ng-show take effect, I found some posts talk about ng-cloak, but it seems not work in my case, probably the ng-cloak is for prevent double curly bracket rather than Element style.

Another way someone talk about is define some style for before AngularJS initialized, but that is kinda hard to manage.

Is there some official way to handle this?


Solution

  • Unless you want to show a loader, ng-cloak should be your solution.

    Official documentation on ng-cloak

    If you still have the issue, you may try to add the css to hide element with ng-cloak inside your html to be sure the browser has it in time.

    If you do that, choose on way to add the ng-cloak. For example add it as class:

    <div ng-show="condition" class="ng-cloak">...</div>
    

    And add this into your html head tag:

    <style> .ng-cloak { display: none !important; } </style>