Avoiding anti-pattern – single module app
When we are starting to study and develop with Angular, it is very common not to pay much attention to the organization and use of the application modules. As we studied at the beginning of this chapter, NgModules are so fundamental to Angular that as soon as we start a project, the Angular CLI creates the first module for the project, AppModule
.
In theory, only this module is necessary for your application to work. From there, we can declare all the components and directives, and import all the libraries that the project might need, as we can see in the following example:
import { NgModule } from '@angular/core'; . . . @NgModule({ declarations: [ AppComponent, StatesSelectorComponent, HomeComponent, SimulationComponent ], imports: [ BrowserModule,AppRoutingModule, BrowserAnimationsModule,HttpClientModule, &...