NgModule Declarations Array List -
We do not declare - Modules, Services, objects, and non-angular helper classes in the module's declarations. Stayed Informed - What Is Modules?
We do not declare - Modules, Services, objects, and non-angular helper classes in the module's declarations. Stayed Informed - What Is Modules?
Syntax for NgModule declaration Array -
declarations: [
AppComponent,
LoginComponent,
MyPipe,
MyDirective
]
The non-Angular classes
and objects as following as -
1. Strings
2. Numbers
3. Functions
4. Entity
Models
5. Configurations
6. and
other helper classes
Note -
You can use directives, components, and pipes classes in a module declaration.
The example of what goes into declarations array
list –
//JavaScript imports directives,
components, and pipes classes
import
{ BrowserModule } from
'@angular/platform-browser';
import
{ NgModule } from
'@angular/core';
import
{ AppComponent } from
'./app.component';
import
{ LoginComponent } from
'./login/login.component';
import
{ MyPipe } from
'./my-pipe.pipe';
import
{ MyDirective } from
'./my-directive.directive';
import
{MySericeService} from
'./my-serice.service';
import{MyModuleModule}
from '../app/my-module/my-module.module';
//AppModule class with the @NgModule
decorator.
@NgModule({
declarations: [
AppComponent,
LoginComponent,
MyPipe,
MyDirective
],
imports: [//DOM
rendering, sanitization, and location
BrowserModule
],
providers: [//service
providers
MySericeService,
MyModuleModule
],
bootstrap: [AppComponent] // bootstrapped
entry component
})
export
class AppModule
{
//exporting app module
}
You can see in the above example, I have created
and declared components, directives and pipes in the @NgModule class using the
CLI commands.
1. ng
g component my-component
2. ng
g pipe my-pipe
3. ng
g directive my-directive
4. ng
g service mySerice
5. ng
g module myModule
These CLI commands automatically imported
components, directives, and pipes classes inside the module.