What are Modules in Angular?
Deepa Chaurasia
Posted on March 16, 2022
Angular doesn't scan automatically all your components and services .
You have to tell Angular what all component, service,directives you have or you are using
Modules does that for you.
Every Angular app must have at least one module (i.e.AppModule)
Modules are basically a place in angular where you group together your components,directives,services etc.
Here you can see appModule.
1. @NgModule-
Angular analyzes ngModules to understand application and it's features.You can't use a feature without including it in @NgModule.
2.Imports-
Imports are important to import other modules into our module like FormsModule,RoutingModule etc.We cannot add every single feature from nodemodule so we import collectively a whole module which contain most of it.
3.Providers
_It defines all services we are providing in our angular app.All the services declared in angular must be inside the _providers of AppModule.
Or you have one other method if you don't wanna write in providers
you have to use
@Injectable({
providedIn: 'root'
})
4. Bootstrap[]
Bootstrap is important for starting your app.It defines which component is available straight in your app **(i.e app-root) **at first.
You can include other components also that's why it's array . But it is not likely to add other component other than AppComponent.
Posted on March 16, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.