|
3 | 3 | A component, directive, or pipe that is referenced by this component would require the compiler to add an import that would lead to a cycle of imports. |
4 | 4 | For example, consider a scenario where a `ParentComponent` references a `ChildComponent` in its template: |
5 | 5 |
|
6 | | -<docs-code header="parent.component.ts" language="angular-ts"> |
| 6 | +```angular-ts {header:"parent.component.ts"} |
7 | 7 | import {Component} from '@angular/core'; |
8 | 8 | import {ChildComponent} from './child.component'; |
9 | 9 |
|
10 | 10 | @Component({ |
11 | | -selector: 'app-parent', |
12 | | -imports: [ChildComponent], |
13 | | -template: '<app-child/>', |
| 11 | + selector: 'app-parent', |
| 12 | + imports: [ChildComponent], |
| 13 | + template: '<app-child/>', |
14 | 14 | }) |
15 | 15 | export class ParentComponent {} |
16 | | -</docs-code> |
| 16 | +``` |
17 | 17 |
|
18 | | -<docs-code header="child.component.ts" language="angular-ts"> |
| 18 | +```angular-ts {header:"child.component.ts"} |
19 | 19 | import {Component, inject} from '@angular/core'; |
20 | 20 | import {ParentComponent} from './parent.component'; |
21 | 21 |
|
22 | 22 | @Component({ |
23 | | -selector: 'app-child', |
24 | | -template: 'The child!', |
| 23 | + selector: 'app-child', |
| 24 | + template: 'The child!', |
25 | 25 | }) |
26 | 26 | export class ChildComponent { |
27 | | -private parent = inject(ParentComponent); |
| 27 | + private parent = inject(ParentComponent); |
28 | 28 | } |
29 | | -</docs-code> |
| 29 | +``` |
30 | 30 |
|
31 | 31 | There is already an import from `child.component.ts` to `parent.component.ts` since the `ChildComponent` references the `ParentComponent` in its constructor. |
32 | 32 |
|
33 | 33 | HELPFUL: The parent component's template contains `<child></child>`. |
34 | 34 | The generated code for this template must therefore contain a reference to the `ChildComponent` class. |
35 | 35 | In order to make this reference, the compiler would have to add an import from `parent.component.ts` to `child.component.ts`, which would cause an import cycle: |
36 | 36 |
|
37 | | -<docs-code language="text"> |
| 37 | +```text |
38 | 38 |
|
39 | 39 | parent.component.ts -> child.component.ts -> parent.component.ts |
40 | 40 |
|
41 | | -</docs-code> |
| 41 | +``` |
42 | 42 |
|
43 | 43 | ## Remote Scoping |
44 | 44 |
|
|
0 commit comments