Understanding the use of @NgModule

This new shit @NgModule silenced me. Previously, I could clearly indicate the dependencies of directives @Componentusing the directives: []meta object attribute @Component. So:

@Component({ /* ... */ })
export class Cmp1 {}

@Component({ /* ... */ })
export class Cmp2 {}

@Component({
  /* ... */
  directives: [Cmp1]
})
export class Cmp3 {}

@Component({
  /* ... */
  directives: [Cmp2, Cmp3]
})
export class Cmp4 {}

Now, under the guise of "convenience", I must now declare @NgModule with all four of these components in one array, for example:

@NgModule({
  declarations: [Cmp1, Cmp2, Cmp3, Cmp4],
  exports: [Cmp4],
  imports: [Cmp1, Cmp2, Cmp3, Cmp4]
})
export class YetAnotherWrapperClass {}

Does the true dependency graph of my components hide? If I do this, how do I know that Cmp3 actually depends on Cmp1? Oh, of course, I can omit some import statements here and there, but it looks like the costs are losing explicit dependencies for each component.

I read the migration guide and the angular modules guide, but I feel that I fundamentally disagree with the @NgModule design decision. Did I miss something?

+4
1

@NgModule() , , . .

, , , NgModule, .

NgModule s, .

import: [Cmp1, Cmp2, Cmp3, Cmp4]

import: [Feature1Module, Feature2Module]

+2

Source: https://habr.com/ru/post/1655889/


All Articles