2

I have been looking at angular seed and I am wondering why do they use both index.ts and modules. from my understanding, they can both be used to export typescript types.

Tom
  • 785
  • 10
  • 26
gilmishal
  • 1,884
  • 1
  • 22
  • 37

1 Answers1

4

These two are entirely unrelated.

index.ts is for TypeScript imports. You need these whenever you use an identifier in a typescript file that is declared in another typescript file.

NgModule is to register directives, components, pipes, and providers in other NgModules.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • so, let's say I have a component, that I only use in my html - it needs to be in a module and not `index.ts`? – gilmishal Nov 15 '16 at 11:08
  • 1
    You don't **need** to use `index.ts` at all. You can also import directly from the file where an identifier is defined. `index.ts` are just for convenience because they make it easier to import several identifiers at once. If you don't refer a components class, you don't need TypeScript imports. If you want to use a component you need it to `declarations` of `NgModule`. To be able to do that you need a TypeScript import, except when the component and the `NgModule` are in the same file. – Günter Zöchbauer Nov 15 '16 at 11:10