What is the purpose of using the providedIn property when creating a service in Angular?

  • It specifies the service's dependencies
  • It specifies the service's instance scope
  • It specifies the service's name
  • It specifies the service's provider
The providedIn property in Angular service metadata is used to specify the service's instance scope. By specifying a module, the service will be a singleton, providing a single shared instance.

To add a third-party library to an Angular project, you can use the _____ command of Angular CLI.

  • ng add
  • ng compile
  • ng generate
  • ng serve
To add a third-party library to an Angular project, you can use the ng add command of Angular CLI.

When an observable is hot, it means that the data is emitted regardless of whether there are any subscribers.

  • buffered
  • emitted
  • paused
  • produced
When an observable is hot, it means that the data is emitted regardless of whether there are any subscribers.

In an Angular reactive form, how can you dynamically add a validator to a form control at runtime?

  • Create a new FormControl instance with the validator
  • It's not possible to add validators at runtime
  • Use the 'Validators' service
  • Use the 'setValidators' method
To dynamically add a validator to a form control in an Angular reactive form, you should use the 'setValidators' method to set the validators for the form control, allowing you to change the validation rules at runtime.

You have an Observable that fetches user data from an API. However, the API occasionally fails. You want to implement a mechanism that retries the API call up to 3 times before handling the error. How would you achieve this?

  • catch(error)
  • repeat(3)
  • retry(3)
  • retryWhen
To retry an observable up to a specified number of times, you can use the retry(3) operator. It retries the source observable up to 3 times before emitting an error if it still fails.

In a large Angular application, you want to ensure that the build process is optimized for production, with minimized bundle size and improved performance. Which Angular CLI command or option would you use?

  • ng build --development
  • ng build --prod --aot
  • ng build --watch
  • ng build --optimize
To optimize a large Angular application for production with minimized bundle size and improved performance, you would use the "ng build --prod --aot" command (option b). This enables Ahead-of-Time (AOT) compilation and produces optimized bundles.

You are building an e-commerce application and want to create a route that shows product details based on the product ID passed in the URL. How would you set this up in your Angular application?

  • Define a route with a parameter like /product/:productId and access the productId using ActivatedRoute.
  • Define a route with a wildcard route that matches /product/* and parse the product ID from the URL.
  • Set up an HTTP interceptor to extract the product ID from the URL and fetch the details.
  • Use Angular Guards to fetch the product details before activating the route.
To show product details based on the product ID in the URL, you should define a route with a parameter like /product/:productId and access the productId using the ActivatedRoute to retrieve the product details.

Using lazy loading, Angular loads additional JavaScript files when the user _______.

  • Clears browser cache
  • Closes a browser tab
  • Logs in to the system
  • Navigates
Using lazy loading, Angular loads additional JavaScript files when the user navigates to a route that is set up for lazy loading.

Which Angular CLI command is used to create a new Angular project?

  • ng create project
  • ng generate project
  • ng new
  • ng start project
The command to create a new Angular project using Angular CLI is ng new. It sets up a new Angular project with the necessary files and dependencies.

Which Angular module must be imported to use template-driven forms?

  • FormsModule
  • HttpClientModule
  • ReactiveFormsModule
  • RouterModule
To use template-driven forms in Angular, you must import the FormsModule. This module provides the necessary directives and services for working with template-driven forms.