Why is it important to unsubscribe from observables in an Angular application?

  • To ensure the observable continues emitting values.
  • To prevent errors in the application.
  • To save memory and prevent memory leaks.
  • To simplify code and improve performance.
It's important to unsubscribe from observables in an Angular application to save memory and prevent memory leaks by cleaning up resources when they are no longer needed.

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.

Which tool is commonly used for executing unit tests in Angular applications?

  • Karma
  • Protractor
  • TypeScript
  • Webpack
The commonly used tool for executing unit tests in Angular applications is Karma. Karma is a test runner that is often used with Angular for running unit tests.

The 'canLoad' Route Guard method checks whether a _____ can be loaded lazily.

  • component
  • directive
  • module
  • service
The 'canLoad' Route Guard method checks whether a module can be loaded lazily. It's used to control the lazy loading of feature modules in Angular applications.