What is the purpose of the root module (AppModule) in an Angular application?
The root module, called AppModule, is the main module that Angular uses to bootstrap and launch the application. It organizes components, services, and other modules needed at startup.
Click to reveal answer
beginner
Which decorator is used to define the root module in Angular?
The @NgModule decorator is used to define the root module. It contains metadata like declarations, imports, providers, and bootstrap arrays.
Click to reveal answer
intermediate
Name the four main properties inside the @NgModule decorator in the root module.
The four main properties are: declarations (components, directives, pipes), imports (other modules), providers (services), and bootstrap (root component to start).
Click to reveal answer
beginner
What does the bootstrap array in AppModule do?
The bootstrap array lists the root component(s) Angular should load and render first when the app starts, usually the AppComponent.
Click to reveal answer
intermediate
Why should the root module import BrowserModule?
BrowserModule provides services needed to run the app in a browser, like rendering and event handling. It must be imported once in the root module.
Click to reveal answer
Which decorator defines an Angular module?
A@Directive
B@Component
C@Injectable
D@NgModule
✗ Incorrect
The @NgModule decorator is used to define modules, including the root module.
What is the main component listed in the bootstrap array of AppModule?
AAppComponent
BMainComponent
CRootComponent
DBootstrapComponent
✗ Incorrect
AppComponent is the default root component bootstrapped by Angular.
Which module must be imported in the root module to run the app in a browser?
ACommonModule
BBrowserModule
CHttpClientModule
DFormsModule
✗ Incorrect
BrowserModule provides essential services for browser apps and is imported once in the root module.
Where do you declare components used in the root module?
Aproviders array
Bimports array
Cdeclarations array
Dbootstrap array
✗ Incorrect
Components, directives, and pipes are declared in the declarations array.
What is the role of the providers array in AppModule?
ARegister services for dependency injection
BList components to display
CImport other modules
DDefine routing paths
✗ Incorrect
The providers array registers services that can be injected throughout the app.
Describe the structure of the root module (AppModule) in Angular and explain the purpose of each main property in the @NgModule decorator.
Think about how Angular organizes app parts in the root module.
You got /5 concepts.
Explain why BrowserModule is important in the root module and what would happen if it was missing.
Consider what Angular needs to display your app in a web browser.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the AppModule in an Angular application?
easy
A. To declare components and import modules needed for the app
B. To style the application globally
C. To handle HTTP requests
D. To manage routing only
Solution
Step 1: Understand the role of AppModule
The AppModule is the root module that organizes the app's components and imports other modules.
Step 2: Identify what AppModule does
It declares components and imports modules needed for the app to work properly.
Final Answer:
To declare components and import modules needed for the app -> Option A
Quick Check:
AppModule organizes components and imports [OK]
Hint: AppModule declares components and imports modules [OK]
Common Mistakes:
Confusing AppModule with styling or HTTP handling
Thinking AppModule only manages routing
Assuming AppModule is for CSS or HTTP only
2. Which of the following is the correct way to define the bootstrap property in @NgModule for starting the app with AppComponent?
easy
A. bootstrap: AppComponent
B. bootstrap = AppComponent
C. bootstrap = [AppComponent]
D. bootstrap: [AppComponent]
Solution
Step 1: Recall the syntax for bootstrap in @NgModule
The bootstrap property expects an array of components to start the app.
Step 2: Match the correct syntax
Using bootstrap: [AppComponent] is the correct way to provide an array with the main component.
Final Answer:
bootstrap: [AppComponent] -> Option D
Quick Check:
Bootstrap uses array syntax [OK]
Hint: Bootstrap needs an array of components [OK]
Common Mistakes:
Using assignment (=) instead of colon (:)
Not wrapping component in an array
Omitting brackets around AppComponent
3. Given this AppModule snippet, what will happen when the app starts?
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
bootstrap: [AppComponent]
})
export class AppModule { }
medium
A. The app will throw a syntax error
B. The app will fail because BrowserModule is missing
C. The app will start and display the AppComponent template
D. The app will start but show a blank page
Solution
Step 1: Check declarations and imports
AppComponent is declared and BrowserModule is imported, which is required for browser apps.
Step 2: Verify bootstrap property
AppComponent is bootstrapped correctly, so it will be the starting component shown.
Final Answer:
The app will start and display the AppComponent template -> Option C
Quick Check:
Proper declarations, imports, and bootstrap means app runs [OK]
Hint: Check declarations, imports, and bootstrap for app start [OK]