Loading

Quipoin Menu

Learn • Practice • Grow

angular / Angular Modules
interview

Q1. What is an Angular module (NgModule)?
An NgModule is a class decorated with @NgModule that defines a compilation context for a set of components, directives, pipes, and services. It helps organize an application into cohesive functional areas. The root module (AppModule) bootstraps the application, while feature modules encapsulate related functionality.

Q2. What are the properties of @NgModule?
Key properties: declarations (components, directives, pipes belonging to this module), imports (other modules needed), exports (parts that should be usable in other modules), providers (services available to the app), bootstrap (root component to bootstrap). Only the root module has bootstrap.

Q3. What is the difference between declarations and imports?
Declarations list the components, directives, and pipes that belong to this module. They must be declared exactly once. Imports list other modules whose exported components, directives, and pipes are needed in this module. For example, to use ngFor, you need to import CommonModule.

Q4. What is a feature module?
A feature module is an NgModule that organizes code related to a specific feature or functionality. It encapsulates components, services, and other artifacts for that feature. Feature modules can be eagerly loaded (included in the main bundle) or lazy-loaded (loaded on demand). This improves maintainability and performance.

Q5. What is the purpose of exports in @NgModule?
The exports array makes some of the module''s components, directives, and pipes available to other modules that import this module. Without exporting, they are only usable within the module itself. For example, CommonModule exports ngIf and ngFor so they can be used everywhere.