How can you prevent memory leaks related to observables when using the async pipe in Angular?
- Angular automatically handles memory leaks with the async pipe.
- Manually unsubscribing from the observable when it's no longer needed.
- There's no way to prevent memory leaks when using the async pipe.
- Using the ngOnDestroy lifecycle hook to unsubscribe from observables.
To prevent memory leaks when using the async pipe in Angular, you should use the ngOnDestroy lifecycle hook to unsubscribe from observables. Failing to unsubscribe from observables can lead to memory leaks, so it's essential to clean up resources properly.
To check if a form control's value has been changed by the user, you can check the _____ property.
- dirty
- pristine
- touched
- value
To check if a form control's value has been changed by the user, you can check the dirty property. The "dirty" state means the control has been touched or modified.
In Angular, you can group together multiple form controls into a single logical unit using _____ .
- ControlUnit
- FormControlGroup
- FormDirective
- FormGroup
In Angular, you can group together multiple form controls into a single logical unit using a FormGroup.
In template-driven forms, how can you customize the update trigger for form controls?
- By using the ControlValueAccessor interface
- By using the FormsModule module
- By using the HTTPInterceptor interface
- By using the ReactiveForms module
In template-driven forms, you can customize the update trigger for form controls by implementing the ControlValueAccessor interface, which allows you to define custom behavior for control updates.
To inject a service into another service, the service being injected should have the _____ decorator.
- @Component()
- @Inject()
- @Injectable()
- @Service()
To inject a service into another service in Angular, the service being injected should have the @Injectable() decorator.
What type of data binding is used when you want to send data from a component's class to its template?
- Event binding
- Interpolation binding
- One-way data binding
- Two-way data binding
In Angular, Two-way data binding is used when you want to send data from a component's class to its template, allowing data to flow in both directions between the component and the template.
When you want to bind a DOM event to a method in your component class, you use event binding.
- event binding
- interpolation binding
- property binding
- two-way binding
In Angular, event binding is used to bind a DOM event to a method in your component class, allowing you to respond to user interactions.
If you need to multicast a single source Observable to multiple observers, you would use a _____.
- forkJoin
- multicast
- subscribe
- toPromise
If you need to multicast a single source Observable to multiple observers, you would use a multicast.
The queryParamsHandling property of the _______ object allows you to specify how Angular should merge query parameters with the current query parameters.
- ActivatedRoute
- ActivatedRouteSnapshot
- Router
- RouterStateSnapshot
The queryParamsHandling property of the Router object allows you to specify how Angular should merge query parameters with the current query parameters.
You are working on an Angular application where a component is making multiple HTTP requests and you notice that the component is causing memory leaks. What approach can you use to solve this issue while making the code cleaner?
- Implement garbage collection strategies
- Manually unsubscribe from observables
- Use HttpClientInterceptor
- Use the async pipe
To solve memory leaks and make the code cleaner, you can use the async pipe, which automatically manages subscriptions and unsubscribes when the component is destroyed.