|
2 | 2 |
|
3 | 3 | TIP: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. |
4 | 4 |
|
5 | | -In addition to using a component directly in a template, you can also dynamically render components. |
6 | | -There are two main ways to dynamically render a component: in a template with `NgComponentOutlet`, |
7 | | -or in your TypeScript code with `ViewContainerRef`. |
| 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 |
| 7 | +be referenced in a template directly) and it depends on some conditions. |
| 8 | + |
| 9 | +There are two main ways to render a component programmatically: in a template using `NgComponentOutlet`, |
| 10 | +or in your TypeScript code using `ViewContainerRef`. |
| 11 | + |
| 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 |
| 15 | +chunks automatically and loaded only when necessary, based on the configured triggers. |
8 | 16 |
|
9 | 17 | ## Using NgComponentOutlet |
10 | 18 |
|
@@ -95,9 +103,11 @@ In the example above, clicking the "Load content" button results in the followin |
95 | 103 |
|
96 | 104 | ## Lazy-loading components |
97 | 105 |
|
98 | | -You can use both of the approaches described above, `NgComponentOutlet` and `ViewContainerRef`, to |
99 | | -render components that are lazy-loaded with a standard |
100 | | -JavaScript [dynamic import](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import). |
| 106 | +HELPFUL: if you want to lazy-load some components, you may consider using the built-in [`@defer` feature](/guide/templates/defer) |
| 107 | +instead. |
| 108 | + |
| 109 | +If your use-case is not covered by the `@defer` feature, you can use either `NgComponentOutlet` or |
| 110 | +`ViewContainerRef` with a standard JavaScript [dynamic import](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/import). |
101 | 111 |
|
102 | 112 | ```angular-ts |
103 | 113 | @Component({ |
|
0 commit comments