Test description

This test assesses your knowledge of Angular. It includes the Angular updates made up to v15.

The questions cover the subscription to observables, working with RxJs operators, usage of forms and differences between them, routing and custom configuration of routes, performance and optimization improvements, dependency injection, lifecycle hooks, data binding, and differential loading.

Topics: RxJs, dependency injection, performance and optimization, differential loading, forms, routing, lifecycle hooks, and directives.

Sample questions

1
Observables are a building block of Angular but can lead to problems if they are not used properly. Given the following context, which line(s) describe(s) a good implementation to unsubscribe from an Observable: (the provided implementation is not optimal, it is presentational only)

@Component ({
  selector: 'my-comp',
  template: '<div>Hi , {{someObs | async }}>' // line 1
})
export class XComponent implements OnInit, OnDestroy {
  someObs$: Observable<any>;
  private unsub: Subscription;
  private subject: Subject = new Subject<void> ();
  constructor (private someService: SomeService) {}
  ngOnInit () {
    this.someObs$ = this.someService.someMethod().pipe(
      takeUntil(this.subject)); // line 2
    this.unsub = this.someObs$.subscribe(); // line 3
  }
  ngOnDestoy () {
    if(this.unsub) {
      this.unsub.unsubscribe();
    }
    this.subject.next();
    this.subject.complete();
  }
}