Challenge - 5 Problems
NgModule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Angular module render?
Given the following Angular module and component setup, what will be rendered on the page?
Angular
import { Component, NgModule } from '@angular/core'; @Component({ selector: 'app-root', template: `<h1>{{ title }}</h1>` }) export class AppComponent { title = 'Hello Angular'; } @NgModule({ declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule {}
Attempts:
2 left
💡 Hint
Check what the bootstrap array does and what the component template contains.
✗ Incorrect
The AppComponent is declared and bootstrapped in AppModule. The template renders the title property inside an <h1> tag, so the output is <h1>Hello Angular</h1>.
📝 Syntax
intermediate2:00remaining
Which NgModule metadata property is missing here?
Identify the missing NgModule metadata property that causes this module to fail loading components from another module.
Angular
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { SharedComponent } from './shared.component'; @NgModule({ declarations: [SharedComponent], imports: [CommonModule] }) export class SharedModule {}
Attempts:
2 left
💡 Hint
Think about how to make components available outside this module.
✗ Incorrect
The exports property is needed to make SharedComponent usable in other modules that import SharedModule. Without it, the component is private to this module.
🔧 Debug
advanced2:00remaining
Why does this Angular module cause a runtime error?
Examine the NgModule metadata and identify the cause of the runtime error when trying to use
FeatureComponent.Angular
import { NgModule } from '@angular/core'; import { FeatureComponent } from './feature.component'; @NgModule({ declarations: [], imports: [], bootstrap: [FeatureComponent] }) export class FeatureModule {}
Attempts:
2 left
💡 Hint
Check what the declarations array controls.
✗ Incorrect
Components must be declared in the declarations array to be recognized by the module. Bootstrapping a component not declared causes a runtime error.
🧠 Conceptual
advanced2:00remaining
What is the role of the 'providers' array in NgModule?
Choose the correct explanation of what the 'providers' array in an NgModule does.
Attempts:
2 left
💡 Hint
Think about how Angular injects services.
✗ Incorrect
The providers array registers services that Angular can inject into components and other services within the module.
❓ lifecycle
expert3:00remaining
What happens if you import the same Angular module twice in different feature modules?
Consider two feature modules both importing a shared module that provides a service. What is the effect on the service instance?
Attempts:
2 left
💡 Hint
Think about how Angular creates service instances when modules are imported multiple times.
✗ Incorrect
When a service is provided in a shared module (not at root), importing that module multiple times creates separate instances of the service for each importing module.