3

I am making an application with angular js. I am binding content in the page using {{ data.content }} method, this works fine, but while loading the web page browser shows the same code in the page.

see the screenshot I've taken while page loading

click here

is there any way to clear this without using ng-bind method ?

EDIT

I have tried this method

1 -added ng-clock for body

<body ng-app="MyApp"   ng-cloack ng-controller="MyController" >

2 -added css style for ng-clock

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

but still the same problem persists.

and I'm using latest version of both chorme and mozilla firefox

3
  • So it's not that it is flashing the uncompiled page then ... It's more the page doesn't work? Any errors in the console? Commented Jan 28, 2015 at 4:12
  • 2
    ng-cloack ? ng-cloak Commented Jan 28, 2015 at 4:13
  • 1
    @PSL oohhh... I'll edit and check Commented Jan 28, 2015 at 4:16

2 Answers 2

8

I believe the issue is the delay in angular compiling the page when it first downloads. Take a look at ngCloak - https://docs.angularjs.org/api/ng/directive/ngCloak.

The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display.

So, add this to your CSS file:

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

And in your html:

<body ng-cloak>

Note, for legacy browser 'support' (e.g. IE7), it would need to be:

<body ng-cloak class="ng-cloak">
Sign up to request clarification or add additional context in comments.

1 Comment

Great! It pays off!
1

Add below code, ngCloak prevent template being displayed while loading.

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

and then call this class in body tag:

<body ng-cloak class="ng-cloak">

https://docs.angularjs.org/api/ng/directive/ngCloak

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.