Angular modules Flashcards
What is an Angular Module
Class with @NgModule decorator.
It
- Organizes the pieces of our application
- Arranges them into blocks
- Extend our application with capabilities from external libraries
- Provide a template resolution environment
- Arrange and re-export
Ng module can be loaded in 2 ways?
Eagerly and Lazy.
Every component, directive or pipe belong to
an angular module
Every application has
At least one angular module and at least one app component
Bootstrap Array
Defines the component that is the starting point of the application and the component that is loaded when app is started
Bootstrap array must
bootstrap at least one component, the root app component
Bootstrap array should
only be used in the root app module, AppModule
Every component, directive and pipe we create is declared by the
Declarations array
Every component, directive and pipe we create must belong to
one and only one angular module
Declarations array only
declare component, directives and pipes
All declared components, directives and pipes are private by default. They are only accessible to other components, directives and pipes declared in the
same module
The template resolution environment is provided by
its own module
Exports array allows us to
share components, directives and pipes with another modules
3rd party modules and system angular modules and our own modules can be
re-exported
If other components need to we can export with exports array
any component, directive or pipe
We can export something without including it in the imports array
True. For example we can export the forms module without including it in the imports array
Importing capabilities from other modules is happening by the imports array
To use components, directives and pipe that one module is exporting to another module
add the module in the imports array
We should import
only what this module needs
Importing a module does not
provide access to its imported modules
Imports are not
Inherited. That is why we sometimes need re-exporting.
Register services provided by Angular or third-party modules
in the imports array. Normally we add a module that registers a service to the imports array of the app module.
This ensures that services are registered on time.
The recommended way to register services is to
use the providedIn property of the @Injectable
The browser module should only be imported
in the root application module
The CommonModule exposes
*ngIf and *ngFor
Routing in feature modules does not use .forRoot but uses
.forChild([]) instead
The purpose of the shared module is to
organize commonly used pieces of our application
In the imports array we add everything needed for the
templates associated with the components of the module.
The main purpose of the app module is to
orchestrate the application as a whole
Browser module is the module that each browser application
must add
Declarations array declares
what belongs to this module
Imports array imports modules
that this module needs
Exports array exports
pieces (components, directives and pipes) to share
Bootstrap array defines
what the index.html needs to start up the application