22
33TIP: This guide assumes you've already read the [ Essentials Guide] ( essentials ) . Read that first if you're new to Angular.
44
5- In addition to using a component directly in a template, you can also dynamically render components
6- programmatically. This is helpful for situations when a component is unknown initially (thus can not
5+ In addition to using a component directly in a template, you can also dynamically render components
6+ programmatically. This is helpful for situations when a component is unknown initially (thus can not
77be referenced in a template directly) and it depends on some conditions.
88
99There are two main ways to render a component programmatically: in a template using ` NgComponentOutlet ` ,
10- or in your TypeScript code using ` ViewContainerRef ` .
10+ or in your TypeScript code using ` ViewContainerRef ` .
1111
12- HELPFUL: for lazy-loading use-cases (for example if you want to delay loading of a heavy component), consider
13- using the built-in [ ` @defer ` feature] ( /guide/templates/defer ) instead. The ` @defer ` feature allows the code
14- of any components, directives, and pipes inside the ` @defer ` block to be extracted into separate JavaScript
12+ HELPFUL: for lazy-loading use-cases (for example if you want to delay loading of a heavy component), consider
13+ using the built-in [ ` @defer ` feature] ( /guide/templates/defer ) instead. The ` @defer ` feature allows the code
14+ of any components, directives, and pipes inside the ` @defer ` block to be extracted into separate JavaScript
1515chunks automatically and loaded only when necessary, based on the configured triggers.
1616
1717## Using NgComponentOutlet
@@ -103,10 +103,10 @@ In the example above, clicking the "Load content" button results in the followin
103103
104104## Lazy-loading components
105105
106- HELPFUL: if you want to lazy-load some components, you may consider using the built-in [ ` @defer ` feature] ( /guide/templates/defer )
106+ HELPFUL: if you want to lazy-load some components, you may consider using the built-in [ ` @defer ` feature] ( /guide/templates/defer )
107107instead.
108108
109- If your use-case is not covered by the ` @defer ` feature, you can use either ` NgComponentOutlet ` or
109+ If your use-case is not covered by the ` @defer ` feature, you can use either ` NgComponentOutlet ` or
110110` ViewContainerRef ` with a standard JavaScript [ dynamic import] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import ) .
111111
112112``` angular-ts
@@ -119,9 +119,11 @@ If your use-case is not covered by the `@defer` feature, you can use either `NgC
119119 </section>
120120 <section>
121121 <h2>Advanced settings</h2>
122- <button (click)="loadAdvanced()" *ngIf="!advancedSettings">
123- Load advanced settings
124- </button>
122+ @if(!advancedSettings) {
123+ <button (click)="loadAdvanced()">
124+ Load advanced settings
125+ </button>
126+ }
125127 <ng-container *ngComponentOutlet="advancedSettings" />
126128 </section>
127129 `
0 commit comments