Job Interview Questions - Angular

Table of Content

  1. [[#What is the difference between a service provided in the root injector versus one provided in a specific component or module?]]
  2. [[#What is the difference between ngOnInit and constructor in a component, and when should you use one over the other?]]
  3. [[#What is the difference between ViewChild and ContentChild decorators, and when would you use each one?]]
What is the difference between a service provided in the root injector versus one provided in a specific component or module?

This approach helps manage dependencies more effectively and keeps your application modular.

What is the difference between ngOnInit and constructor in a component, and when should you use one over the other?

So in short, use constructor for basic setup and dependency injection, and use ngOnInit for any logic that needs to happen after component's inputs are set.

What is the difference between ViewChild and ContentChild decorators, and when would you use each one?

In summary, you'd use ViewChild for elements inside your own template, and ContentChild for elements that come from outside, via content projection.