What is the main difference between hot and cold observables in Angular?
- Cold observables emit values when subscribed to.
- Cold observables share their subscription with all subscribers.
- Hot observables emit values when subscribed to.
- Hot observables share their subscription with all subscribers.
The main difference between hot and cold observables is that hot observables emit values when subscribed to, while cold observables emit values individually for each subscriber.
Karma can automatically watch your files for changes and re-run tests using the _____ configuration option.
- Auto
- Refresh
- Watch
- Update
Karma can automatically watch your files for changes and re-run tests using the Watch configuration option, improving test efficiency.
Jasmine allows you to set up initial conditions for your tests in a block known as _____.
- Arrange
- Before
- Prepare
- Setup
In Jasmine, you can set up initial conditions for your tests in a block known as Arrange to ensure a clean test environment.
You are building a real-time dashboard that fetches data from multiple sources. You want to update the UI as soon as any of the data sources emit a new value. Which RxJS operator would be most suitable for this use case?
- concatMap
- exhaustMap
- mergeMap
- switchMap
In this scenario, you should use switchMap, which switches to the latest observable whenever a new one arrives, effectively updating the UI as soon as any source emits new data.
In a Protractor test, how can you interact with a button element on a webpage?
- browser.findElement(By.button())
- button.click()
- element(by.button())
- element(by.id())
To interact with a button element in Protractor, you typically use the button.click() method to simulate a click on the button.
When you want an Observable to emit a sequence of values over time, you would use _____.
- interval()
- map()
- of()
- timer()
When you want an Observable to emit a sequence of values over time, you would use interval(). The interval() operator emits values at specified time intervals.
What can a Route Resolver return to indicate that the route data is not available?
- Empty object
- Null
- Observable with an error
- Undefined
A Route Resolver can return an Observable with an error to indicate that the route data is not available or there was an issue fetching it.
How can you handle errors within a Route Resolver?
- Handle errors outside the resolver
- Log the error to the console
- Redirect to an error page
- Rethrow the error to the component
To handle errors within a Route Resolver, you can rethrow the error to the component using an observable with catchError.
Angular's change detection mechanism ensures that the _____ is in sync with the component's state.
- DOM
- model
- template
- view
Angular's change detection mechanism ensures that the DOM is in sync with the component's state, ensuring that the view is up-to-date.
To define custom validators in reactive forms, you need to implement a function that returns a/an _____ .
- Array
- Object
- Observable
- ValidatorFn
In reactive forms, custom validators are implemented as functions that return a ValidatorFn, which is used to validate form controls.