0
0
Angularframework~20 mins

Declarations, imports, and exports in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Declarations Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Angular standalone component?
Consider this Angular standalone component code. What will be rendered in the browser?
Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-counter',
  standalone: true,
  template: `<button (click)="increment()">Count: {{ count() }}</button>`
})
export class CounterComponent {
  count = signal(0);
  increment() {
    this.count.update(c => c + 1);
  }
}
AA button showing 'Count: 0' initially and increments the number on each click.
BA button showing 'Count: 0' but does not update on clicks.
CA button showing 'Count: 1' initially and increments the number on each click.
DThe component throws a runtime error because signals cannot be used in standalone components.
Attempts:
2 left
💡 Hint
Remember that signals hold reactive state and update the template automatically.
📝 Syntax
intermediate
1:30remaining
Which import statement correctly imports the inject function in Angular 17+?
You want to use the new inject() function in Angular 17 standalone components. Which import statement is correct?
Aimport { inject } from '@angular/common';
Bimport { inject } from '@angular/forms';
Cimport { inject } from '@angular/core';
Dimport { inject } from '@angular/platform-browser';
Attempts:
2 left
💡 Hint
The inject function is part of Angular's core dependency injection system.
🔧 Debug
advanced
2:30remaining
Why does this Angular component fail to compile?
Look at this Angular standalone component code. Why does it fail to compile?
Angular
import { Component } from '@angular/core';

@Component({
  selector: 'app-sample',
  standalone: true,
  template: `<p>Hello World</p>`
})
export class SampleComponent {
}

@NgModule({
  declarations: [SampleComponent],
  imports: [],
  exports: [SampleComponent]
})
export class SampleModule {}
AThe selector 'app-sample' is invalid for standalone components.
BThe component is missing the imports array in @Component decorator.
CThe template syntax is incorrect and causes a parsing error.
DStandalone components cannot be declared in NgModules, so declaring SampleComponent in declarations causes an error.
Attempts:
2 left
💡 Hint
Standalone components are self-contained and should not be declared in NgModules.
🧠 Conceptual
advanced
2:00remaining
What happens when you export a standalone component from an NgModule?
Given a standalone component and an NgModule that exports it, what is the effect?
AStandalone components cannot be exported from NgModules; this causes a compile error.
BThe standalone component can be used in other modules that import this NgModule.
CExporting a standalone component from an NgModule duplicates the component and causes runtime errors.
DThe component becomes non-standalone and requires declarations in every module.
Attempts:
2 left
💡 Hint
Think about how exports in NgModules share components with other modules.
state_output
expert
3:00remaining
What is the value of 'message' after this Angular signal update sequence?
Given this Angular component code using signals, what is the final value of the 'message' signal after running the update calls?
Angular
import { Component, signal } from '@angular/core';

@Component({
  selector: 'app-msg',
  standalone: true,
  template: `{{ message() }}`
})
export class MsgComponent {
  message = signal('start');

  constructor() {
    this.message.update(msg => msg + '->first');
    this.message.set('reset');
    this.message.update(msg => msg + '->second');
  }
}
A"reset->second"
B"start->first->second"
C"start->first"
D"reset"
Attempts:
2 left
💡 Hint
Remember that set replaces the signal value, update modifies the current value.