Search code examples
angularjsangular-directiveng-showangular-ng-if

make an element with ng-if start hidden (prevent it from showing during page load)


When i want to make something start as hidden with ng-show you can just add class="ng-hide" so the css will hide the element beforehand. This way an element won't be shown when the page is still loading

I want to do the same thing using ng-if but i don't know how to do it


Solution

  • As Michiel suggested, using the ngCloak directive is the solution.
    Just add ng-cloak to the class attribute of the tag you want to keep hidden while your application is loading.

    <div class="ng-cloak">test</div>
    

    For more details: https://docs.angularjs.org/api/ng/directive/ngCloak