Skip to content

Commit bfff117

Browse files
feat: Add information about EntryComponents, in example2 add ngComponentOutlet sample.
1 parent fb19bac commit bfff117

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ export function ɵɵreference<T>(index: number) {
138138
_angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵɵtextInterpolate"](ctx.checkView(_r1, "Component"));
139139
```
140140
141+
## EntryComponents
142+
Specifies a list of components that should be compiled when this module is defined. For each component listed here, Angular will create a ComponentFactory and store it in the ComponentFactoryResolver.
143+
144+
> In Angular 9 (Ivy) EntryComponent has been deprecated and there is no need to put dynamic components to it because Factory is created in a static field on the component itself.
145+
- [EntryComponent - angular/angular/issues/33715](https://github.com/angular/angular/issues/33715#issuecomment-616017433 )
146+
141147
## Sources
142148
- [ElementRef, TemplateRef, ViewRef, ComponentRef and ViewContainerRef](https://gist.github.com/rajaramtt/f2bf4bb420ced6198334622d32695554)- [ng_template_outlet.ts](https://github.com/angular/angular/blob/master/packages/common/src/directives/ng_template_outlet.ts)
143149
- [compiler/src/template_parser/template_parser](https://github.com/angular/angular/blob/master/packages/compiler/src/template_parser/template_parser.ts#L369​)
@@ -148,4 +154,5 @@ export function ɵɵreference<T>(index: number) {
148154
- [angular-ngfor-template-element](https://ultimatecourses.com/blog/angular-ngfor-template-element) Google
149155
- [benefit-of-using-ng-container-vs-template](https://stackoverflow.com/questions/54029503/benefit-of-using-ng-container-vs-template)
150156
- [Angular ng-template, ng-container and ngTemplateOutlet](https://blog.angular-university.io/angular-ng-template-ng-container-ngtemplateoutlet/)
151-
- [angular-ng-content](https://blog.angular-university.io/angular-ng-content/)
157+
- [angular-ng-content](https://blog.angular-university.io/angular-ng-content/)
158+
- [Module EntryComponents](https://angular.io/guide/ngmodule-faq#when-do-i-add-components-to-entrycomponents)

src/app/example1/example1.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<pre>
2-
<h4>Reminder</h4>
2+
<h4>Template Reminder</h4>
33

44
> Native HTML Element
55
<button #view1>Simple Button {{checkView(view1, "Native HTML Element")}}</button>

src/app/example2/example2.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ <h4>Template & Container Use Cases</h4>
3939

4040
> Use Case n° 5.2 (use a container+template)
4141
<ng-container *ngTemplateOutlet="amazingTemplate"></ng-container>
42+
43+
> Use Case n° 5.3 (use a container+component)
44+
<ng-container *ngComponentOutlet="SimpleButtonComponent"></ng-container>
4245

4346
<ng-template #amazingTemplate>
4447
<div *ngFor="let item of ['content']">
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { Component } from '@angular/core';
2+
import { SimpleButtonComponent } from '@app/example1/simple-button/simple-button.component';
23

34
@Component({
45
selector: 'app-example2',
56
templateUrl: './example2.component.html',
67
styleUrls: ['../example1/example1.component.sass']
78
})
89
export class Example2Component {
10+
// This field is necessary to expose SimpleButtonComponent to the template.
11+
SimpleButtonComponent = SimpleButtonComponent;
12+
913
constructor() { }
1014
}

src/app/example2/example2.module.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { Example2Component } from './example2.component';
4-
5-
4+
import { SimpleButtonModule } from '@app/example1/simple-button/simple-button.module';
5+
// import { SimpleButtonComponent } from '@app/example1/simple-button/simple-button.component';
66

77
@NgModule({
88
declarations: [Example2Component],
99
exports: [Example2Component],
1010
imports: [
11-
CommonModule
12-
]
11+
CommonModule,
12+
SimpleButtonModule
13+
],
14+
// entryComponents: [
15+
// SimpleButtonComponent
16+
// ]
1317
})
1418
export class Example2Module { }
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<!-- <app-example1>
1+
<!-- Template Reminder -->
2+
<app-example1>
23
<button #view1>Simple Button {{checkView(view1, "Sandbox")}}</button>
34
</app-example1>
45

5-
<app-example2></app-example2> -->
6+
<!-- Template & Container Use Cases -->
7+
<app-example2></app-example2>
68

9+
<!-- Dynamic contents - Full -->
710
<app-example3></app-example3>

0 commit comments

Comments
 (0)