0
0
Angularframework~20 mins

Importing dependencies directly in Angular - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
Correct import syntax for Angular HttpClient
Which option correctly imports HttpClient from Angular's @angular/common/http package?
Aimport HttpClient from '@angular/http';
Bimport { HttpClient } from '@angular/common/http';
Cimport { HttpClientModule } from '@angular/common/http';
Dimport HttpClient from '@angular/common/http';
Attempts:
2 left
💡 Hint
Angular uses named imports for HttpClient from the common/http package.
component_behavior
intermediate
2:00remaining
Effect of missing import on Angular component
What happens if you forget to import FormsModule in an Angular module but use [(ngModel)] in a component template?
AThe app compiles and runs normally without any errors.
BThe app compiles but <code>ngModel</code> binding does not work and throws a runtime error.
CThe app fails to compile with a template parse error about <code>ngModel</code>.
DThe app compiles but <code>ngModel</code> silently ignores changes.
Attempts:
2 left
💡 Hint
Angular requires importing modules that provide template directives.
🔧 Debug
advanced
2:30remaining
Identify the import error causing compilation failure
Given this Angular component code, which import mistake causes a compilation error when injecting Router?
import { Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-home',
  template: ``
})
export class HomeComponent {
  constructor(private router: Router) {}
  goHome() { this.router.navigate(['/']); }
}
AImporting Router from '@angular/common' causes compilation error.
BImporting Router from '@angular/router' is correct; no error here.
CImporting Router from '@angular/core' causes compilation error.
DNot importing Router at all causes compilation error.
Attempts:
2 left
💡 Hint
Router must be imported from the correct Angular package.
🧠 Conceptual
advanced
2:30remaining
Why use standalone components with direct imports in Angular 17+?
What is the main advantage of importing dependencies directly in standalone Angular components instead of using NgModules?
AIt disables lazy loading of components.
BIt forces all components to share the same global scope.
CIt requires manually declaring components in NgModules.
DIt reduces boilerplate and improves tree-shaking for smaller bundles.
Attempts:
2 left
💡 Hint
Think about bundle size and code simplicity.
state_output
expert
3:00remaining
Output of Angular component with direct service import and injection
Consider this Angular service and component:
import { Injectable } from '@angular/core';

@Injectable({ providedIn: 'root' })
export class CounterService {
  count = 0;
  increment() { this.count++; }
}

import { Component } from '@angular/core';
import { CounterService } from './counter.service';

@Component({
  selector: 'app-counter',
  template: ``
})
export class CounterComponent {
  constructor(public counter: CounterService) {}
  increment() { this.counter.increment(); }
}
What will be displayed on the button after clicking it three times?
ACount: 3
BCount: undefined
CCount: 1
DCount: 0
Attempts:
2 left
💡 Hint
The service is singleton and state is shared.