0
0
Angularframework~20 mins

NgModule decorator and metadata in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NgModule Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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 {}
A<h1>Hello Angular</h1>
BNothing renders because bootstrap is missing BrowserModule
CError: AppComponent not declared
D<app-root></app-root>
Attempts:
2 left
💡 Hint
Check what the bootstrap array does and what the component template contains.
📝 Syntax
intermediate
2: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 {}
Aproviders: [SharedComponent]
Bschemas: [SharedComponent]
Cbootstrap: [SharedComponent]
Dexports: [SharedComponent]
Attempts:
2 left
💡 Hint
Think about how to make components available outside this module.
🔧 Debug
advanced
2: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 {}
AFeatureComponent is not declared in declarations array
BFeatureComponent should be in imports array
Cbootstrap array cannot contain components
DNgModule must have providers array
Attempts:
2 left
💡 Hint
Check what the declarations array controls.
🧠 Conceptual
advanced
2:00remaining
What is the role of the 'providers' array in NgModule?
Choose the correct explanation of what the 'providers' array in an NgModule does.
AIt lists modules that this module depends on.
BIt declares components that belong to the module.
CIt registers services that are available for dependency injection throughout the module.
DIt specifies components to bootstrap when the app starts.
Attempts:
2 left
💡 Hint
Think about how Angular injects services.
lifecycle
expert
3: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?
AThe service instance is shared as a singleton across the app.
BEach feature module gets its own separate instance of the service.
CAngular throws a runtime error due to duplicate imports.
DThe service is not available in either feature module.
Attempts:
2 left
💡 Hint
Think about how Angular creates service instances when modules are imported multiple times.