NG Interview Set I - NgModules Questions Flashcards
NG Interview Set I - NgModules Questions
What is the purpose of NgModule?
- It’s to give Angular information on a particular module’s contents, through decorator properties like: declarations, imports, exports, providers, etc.
How do you decide to create a new NgModule?
- Typically for a nontrivial feature in an application, that will involve a collection of related components and services
What are the attributes that you can define in an NgModule annotation?
- Declarations, imports, exports, providers, bootstrap
What is the difference between a module’s forRoot() and forChild() methods and why do you need it?
- forRoot and forChild are conventional names for methods that deliver different import values to root and feature modules
What would you have in a shared module?
- Common components, directives, and pipes used in other modules in your application
What would you not put shared module?
- Services that should not have multiple instances created for the application
What module would you put a singleton service whose instance will be shared throughout the application (e.g. ExceptionService andLoggerService)?
- Root Module
What is the purpose of exports in an NgModule?
- Provide components, directives, pipes to other modules for their usage
Why is it (potentially) bad if SharedModule provides a service to a lazy loaded module?
- You will have two instances of the service in your application, which is often not what you want
Can we import a module twice?
- Yes, and the latest import will be what is used
Can you re-export classes and modules?
- Yes
What kind of classes can you import in an angular module?
- Components, pipes, directives
What is the providers property used for in a module’s NgModule metadata?
- To provide a list of service cerators that this module contributes to the global collection of services
What is bootstrapping in Angular?
- The mechanism that launches the application in Angular, loading the root module (typically called AppModule) which loads one or more bootstrapped components into the application’s DOM