What is the exact meaning of export keyword in Angular 2\TypeScript?
Yes you are right by using export keyword before your typescript class you can use that class somewhere else .. in your project
Angular imports/exports and TypeScript imports/exports are two different concepts.
TypeScript imports/exports work at language level to make it clear what a used identifier references exactly. This is entirely unrelated to Angular.
So, if you use FormsModule
there can't be any ambiguity, what FormsModule
is meant. If there is more than one FormsModule
in your code or any of your dependencies, then you need to make it clear with imports which one is meant. You can't import 2 FormsModule
from different locations without disambiguation (for example using as foo
in the import and then reference it using foo.FormsModule
).
This way you can use code from arbitrary 3rd-party libraries and avoid name collisions.
Angular imports/exports are used to make the content of one module available to be used in another module.
Your:
imports: [
FormsModule,
AuthRoutingModule
]
Allows you to use the directives from FormsModule
and AuthRoutingModule
in AuthModule
and registers the services provided by these modules in the AppModule
scope or the closed lazy-loaded root scope.
If you reference any of Angulars directives or services in TypeScript code, you also need to add TypeScript imports. Above FormsModule
and AuthRoutingModule
need to be imported with TypeScript imports, to make the Angular imports: [...]
work.
For example like
<form #f="ngForm">
<input type="text">
</form>
works only if FormsModule
is listed in imports: [ ... ]
of your current module.
There is no TypeScript import required, because there is no TypeScript code.