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.
Asked
Active
Viewed 812 times
2
1 Answers
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 NgModule
s.

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
-
1You 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