Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 ngcloak un-compiled elements? [duplicate]

Tags:

angular

AngularJS 1.x has ngCloak directive, which is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form.

Does Angular 2 have any such directive or functionality to prevent such raw(uncompiled) form display.

like image 272
refactor Avatar asked Sep 09 '16 10:09

refactor


3 Answers

Angular2 desn' have ngCloak,

instead you can use ?. operator (use it with object).

{{user?.name}}

AND/OR

you can use *ngIf (as of now)

<div *ngIf="name"> {{name}}</div>
like image 165
Nikhil Shah Avatar answered Jan 04 '23 00:01

Nikhil Shah


There are two types of compilations in Angular2 ,Just-in-Time(JiT) and Ahead-of-Time(AoT). Just-in-Time is the default compilation.

JiT compilation incurs a runtime performance penalty.Views take longer to render because of the in-browser compilation step. The application is bigger because it includes the Angular compiler and a lot of library code that the application won't actually need. Bigger apps take longer to transmit and are slower to load.

With AoT, the browser downloads a pre-compiled version of the application. The browser loads executable code so it can render the application immediately, without waiting to compile the app first.

If we go with Ahead-of-Time compilation instead of Just-in-Time compilation, we can prevent such raw(uncompiled) form of display.

This link provides more information

like image 45
refactor Avatar answered Jan 04 '23 00:01

refactor


You can prevent rendering of html by using *ngIf until the corresponding object is loaded:

<div *ngIf="dataList">
<>....</>
</div>
like image 25
Dilip Nannaware Avatar answered Jan 03 '23 22:01

Dilip Nannaware