So I'm using RC5, and when embracing things seems to go pretty decently for now I ran into an issue which I'm not sure if I'm doing something wrong or is working as intended;
Before it was possible to make form directives etc. globally available. Nowadays we started using NgModule. It seems though that I can't use FormsModule and ReactiveFormsModule globally, either in AppModule nor in a SharedModule. I need to import it in every single module I create.
Is this as intended?
Should I import BrowserModule or CommonModule ? link. The root application module, AppModule , of almost every browser application should import BrowserModule from @angular/platform-browser . BrowserModule provides services that are essential to launch and run a browser application.
BrowserModule and CommonModule link BrowserModule imports CommonModule , which contributes many common directives such as ngIf and ngFor . Additionally, BrowserModule re-exports CommonModule making all of its directives available to any module that imports BrowserModule .
NgModules configure the injector and the compiler and help organize related things together. An NgModule is a class marked by the @NgModule decorator. @NgModule takes a metadata object that describes how to compile a component's template and how to create an injector at runtime.
According to this NgModule doc it is as intended,
so if you are using multiple NgModule heirarchy in your app, you will need to create a SharedModule
and import/export all the global Modules/Components/Directives/Pipes
in it.
then import this module in every Module that you want to share it with.
You can read the docs for more clarification.
You should add FormsModule
and ReactiveFormsModule
to your SharedModule
exports, then you need to import your SharedModule
into your other modules. That way, you will be able to use desired directives globally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With