4

I have 4 forms of which using angular ng-hide and ng-show to display each when needed. But when the page loads initially it displays all forms while loading and only hide them when loading completes. It really looks crappy while loading. Is there a way i can prevent this from happen?

3
  • ngCloak was designed for that Commented May 23, 2016 at 14:46
  • How do i apply it to forms? Having 3 forms Commented May 23, 2016 at 15:10
  • Usually, you want to apply it to whole app, just for a time, while angular is not here. But you can apply it to what you want - just add class or attribute... See docs/@asdf_enel_hak's answer below for css rule Angular remove this stuff when it's loaded and will be applied standard ngShow/ngHide features. Commented May 23, 2016 at 15:14

2 Answers 2

1

ng-cloak will work for you

example:

in your css:

[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  display: none !important;
}

and in your code:

<div id="template1" ng-cloak>{{ 'hello' }}</div>
Sign up to request clarification or add additional context in comments.

Comments

1

CSS:

[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  display: none !important;
}

HTML:

<body ng-cloak> ... </body>

will work, but it will hide whole body. https://docs.angularjs.org/api/ng/directive/ngCloak:

The directive can be applied to the element, but the preferred usage is to apply multiple ngCloak directives to small portions of the page to permit progressive rendering of the browser view.

so it's better to apply ng-cloak to particular elements:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.