NG Interview Set I - NgModules Questions Flashcards

NG Interview Set I - NgModules Questions

1
Q

What is the purpose of NgModule?

A
  • It’s to give Angular information on a particular module’s contents, through decorator properties like: declarations, imports, exports, providers, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you decide to create a new NgModule?

A
  • Typically for a nontrivial feature in an application, that will involve a collection of related components and services
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the attributes that you can define in an NgModule annotation?

A
  • Declarations, imports, exports, providers, bootstrap
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between a module’s forRoot() and forChild() methods and why do you need it?

A
  • forRoot and forChild are conventional names for methods that deliver different import values to root and feature modules
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What would you have in a shared module?

A
  • Common components, directives, and pipes used in other modules in your application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What would you not put shared module?

A
  • Services that should not have multiple instances created for the application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What module would you put a singleton service whose instance will be shared throughout the application (e.g. ExceptionService andLoggerService)?

A
  • Root Module
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of exports in an NgModule?

A
  • Provide components, directives, pipes to other modules for their usage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is it (potentially) bad if SharedModule provides a service to a lazy loaded module?

A
  • You will have two instances of the service in your application, which is often not what you want
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can we import a module twice?

A
  • Yes, and the latest import will be what is used
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can you re-export classes and modules?

A
  • Yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What kind of classes can you import in an angular module?

A
  • Components, pipes, directives
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the providers property used for in a module’s NgModule metadata?

A
  • To provide a list of service cerators that this module contributes to the global collection of services
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is bootstrapping in Angular?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly