DEV Community

Deepa Chaurasia
Deepa Chaurasia

Posted on

What are Modules in Angular?

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.

Image description

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

Image description

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.

Top comments (0)