Which decorator allows you to listen for events from the children of the current component?

  • @HostListener()
  • @Input()
  • @Output()
  • @ViewChild()
The @ViewChild() decorator in Angular allows you to listen for events and interact with the children of the current component. It is commonly used to access and manipulate child components, directives, or elements within the template. While @Input() and @Output() decorators are used for communication between parent and child components, and @HostListener() is used for listening to events on the host element, none of these directly provide access to children components.

Which Angular feature allows you to load certain modules only when they are needed?

  • Dependency Injection
  • Lazy Loading
  • Observables
  • Routing
The Angular feature that allows you to load certain modules only when they are needed is Lazy Loading. Lazy loading helps optimize your application's performance by loading modules on-demand, making it a key technique for improving user experience.

A developer in your team used a custom form control but found that the valueChanges observable isn't emitting values when the control's value changes. What might be the potential reason and how would you resolve it?

  • The developer forgot to subscribe to the valueChanges observable.
  • The developer didn't specify a unique ID for the custom form control.
  • The developer is using a deprecated version of Angular.
  • The custom form control is missing the FormControlName directive in the template.
The potential reason for the valueChanges observable not emitting values when the custom form control's value changes could be that the custom form control is missing the FormControlName directive in the template. This directive binds the control to the form and allows it to propagate changes. Options a and b are not the typical reasons for this issue, and option c is unlikely unless there are other symptoms of a deprecated version. It's crucial to ensure that the custom form control is correctly integrated into the Angular form template.

After applying AOT compilation, a developer notices that certain dynamic components no longer render correctly. What could be a potential reason for this?

  • AOT compilation doesn't affect dynamic components
  • Dynamic components rely on JIT compilation
  • Incorrect use of NgModule declarations
  • Incorrect use of lazy loading
After AOT compilation, it's essential to ensure that all components, including dynamic ones, are properly declared in Angular's NgModule metadata. If a dynamic component is not declared correctly, it may not render as expected.

Which RxJS operator is best suited for handling side effects?

  • filter
  • map
  • reduce
  • tap
The tap operator is specifically designed for handling side effects in RxJS. It allows you to perform actions or computations without affecting the original data stream. Common side effects include logging, making HTTP requests, or modifying external state.

How can you serve your Angular application locally using Angular CLI?

  • ng build
  • ng run
  • ng serve
  • ng start
To serve your Angular application locally during development, you should use the ng serve command. This command compiles your application, starts a development server, and opens it in a web browser. It also provides features like automatic reloading when you make code changes.

What is the primary purpose of services in Angular?

  • Defining component templates.
  • Handling HTTP requests and sharing data.
  • Managing the application's routing.
  • Storing configuration settings.
The primary purpose of services in Angular is to handle HTTP requests and share data between different components. Services act as a central place to manage data and provide methods for components to interact with that data. While services can be used for other purposes like routing or storing configuration, their primary role is data management and communication between parts of an Angular application.

To dynamically load and view a component without adding it to a module's entry components, you would utilize ______.

  • ComponentFactoryResolver
  • DynamicComponentLoader
  • ComponentFactory
  • ComponentLoader
In Angular, to dynamically load and view a component without adding it to a module's entry components, you would utilize the ComponentFactoryResolver. This service provides a way to create component factories dynamically, which can then be used to create instances of components at runtime. The other options are not commonly used for this purpose.

How can you access the value of a template-driven form control in the component class?

  • Using the formControlName directive.
  • Using the @ViewChild decorator.
  • Using the [(ngModel)] directive.
  • Using the Validators module.
To access the value of a template-driven form control in the component class, you can use the @ViewChild decorator. This allows you to reference the form control in the component, giving you access to its value and properties. While the other options are related to forms and validation in Angular, they do not directly provide a way to access the form control's value in the component class.

When using ChangeDetectionStrategy.OnPush, Angular relies on ________ checks to determine component updates.

  • Asynchronous
  • Manual
  • Reference
  • Regular
When using ChangeDetectionStrategy.OnPush in Angular, the framework relies on asynchronous checks to determine component updates. This means that Angular will trigger change detection for a component when asynchronous events, such as user interactions or observable data changes, occur. This strategy is valuable for optimizing performance by reducing unnecessary checks.