forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.directive.ng:cloak.html
47 lines (43 loc) · 2.42 KB
/
angular.directive.ng:cloak.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<h1>angular.directive.ng:cloak</h1>
<div class="angular-directive-ng-cloak"><h2>Description</h2>
<div class="description"><p>The <code>ng:cloak</code> 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.</p>
<p>The directive can be applied to the <code><body></code> element, but typically a fine-grained application is
prefered in order to benefit from progressive rendering of the browser view.</p>
<p><code>ng:cloak</code> works in cooperation with a css rule that is embedded within <code>angular.js</code> and
<code>angular.min.js</code> files. Following is the css rule:</p><div ng:non-bindable><pre class="brush: js;">
[ng\:cloak], .ng-cloak {
display: none;
}
</pre></div><p>When this css rule is loaded by the browser, all html elements (including their children) that
are tagged with the <code>ng:cloak</code> directive are hidden. When Angular comes across this directive
during the compilation of the template it deletes the <code>ng:cloak</code> element attribute, which
makes the compiled element visible.</p>
<p>For the best result, <code>angular.js</code> script must be loaded in the head section of the html file;
alternatively, the css rule (above) must be included in the external stylesheet of the
application.</p>
<p>Legacy browsers, like IE7, do not provide attribute selector support (added in CSS 2.1) so they
cannot match the <code>[ng\:cloak]</code> selector. To work around this limitation, you must add the css
class <code>ng-cloak</code> in addition to <code>ng:cloak</code> directive as shown in the example below.</p></div>
<h2>Usage</h2>
<div class="usage"><pre class="brush: js; html-script: true;"><ANY ng:cloak>
...
</ANY></pre>
</div>
<h2>Example</h2>
<div class="example"><doc:example>
<pre class="doc-source">
<div id="template1" ng:cloak>{{ 'hello' }}</div>
<div id="template2" ng:cloak class="ng-cloak">{{ 'hello IE7' }}</div>
</pre>
<pre class="doc-scenario">
it('should remove the template directive and css class', function() {
expect(element('.doc-example-live #template1').attr('ng:cloak')).
not().toBeDefined();
expect(element('.doc-example-live #template2').attr('ng:cloak')).
not().toBeDefined();
});
</pre>
</doc:example></div>
</div>