0
0
Angularframework~20 mins

Migrating from NgModules in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Standalone Angular Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
Standalone Component Import Behavior
Consider an Angular standalone component ProfileCard that you want to use inside another standalone component Dashboard. How should you import ProfileCard into Dashboard to display it correctly?
Angular
import { Component } from '@angular/core';
import { ProfileCard } from './profile-card.component';

@Component({
  selector: 'app-dashboard',
  standalone: true,
  imports: [/* What goes here? */],
  template: `<app-profile-card></app-profile-card>`
})
export class Dashboard {}
ADeclare ProfileCard in the declarations array of Dashboard's NgModule.
BAdd ProfileCard to the imports array in the @Component decorator of Dashboard.
CAdd ProfileCard to the providers array in Dashboard component.
DNo import needed; Angular automatically detects standalone components.
Attempts:
2 left
💡 Hint
Standalone components must be explicitly imported in the imports array of the component using them.
📝 Syntax
intermediate
2:00remaining
Correct Syntax for Standalone Component Declaration
Which of the following is the correct way to declare a standalone Angular component named AlertBox?
A@Component({ selector: 'app-alert-box', standalone: true, template: `<p>Alert!</p>` }) export class AlertBox {}
B@Component({ selector: 'app-alert-box', standalone: true }) export class AlertBox {}
C@Component({ selector: 'app-alert-box', standalone: true, templateUrl: 'alert-box.html' }) export class AlertBox {}
D@Component({ selector: 'app-alert-box', standalone: false, template: `<p>Alert!</p>` }) export class AlertBox {}
Attempts:
2 left
💡 Hint
Standalone components require the standalone flag set to true and a template or templateUrl.
🔧 Debug
advanced
2:00remaining
Error When Using a Standalone Component Without Import
You have a standalone component UserCard and a standalone component AppRoot. You use <app-user-card> inside AppRoot template but forget to import UserCard in AppRoot. What error will Angular throw at runtime?
ANo error; Angular automatically resolves standalone components
BNullInjectorError: No provider for UserCard
CSyntaxError: Unexpected token '<' in template
DTemplate parse error: 'app-user-card' is not a known element
Attempts:
2 left
💡 Hint
Angular needs components to be imported to recognize their selectors in templates.
state_output
advanced
2:00remaining
Effect of Removing NgModule on Service Injection
You migrate a feature module to standalone components and remove its NgModule. You have a service DataService provided in the removed module. What happens to the service injection in components that used to rely on that module?
AService injection fails with No provider error unless the service is provided elsewhere.
BService injection continues to work because Angular automatically provides services globally.
CService injection works only if the service is provided in the component's providers array.
DService injection works only if the service is provided in the root injector.
Attempts:
2 left
💡 Hint
Removing the NgModule removes its providers unless they are moved or provided elsewhere.
🧠 Conceptual
expert
2:00remaining
Advantages of Standalone Components Over NgModules
Which of the following is NOT an advantage of migrating from NgModules to standalone components in Angular?
ASimplifies component dependencies by importing only what is needed directly in components.
BEliminates the need for NgModule metadata, reducing boilerplate code.
CAutomatically improves runtime performance by lazy loading all components.
DEnables easier tree-shaking and smaller bundle sizes.
Attempts:
2 left
💡 Hint
Consider what standalone components change and what they do not automatically do.