To listen for changes on a form control, you can subscribe to its ______ observable.
- statusChangesObservable
- valueChangesObservable
- errorsObservable
- formChangesObservable
In reactive forms, you can listen for changes on a form control by subscribing to its "valueChanges" observable. This allows you to track changes in the value of the form control over time. The other options do not represent the correct observables to listen for changes on a form control in reactive forms.
For configuring proxies during development to bypass CORS issues, you'd modify the ______ file in an Angular CLI project.
- app.module.ts
- environment.prod.ts
- proxy.conf.json
- tsconfig.json
To configure proxies for handling CORS issues during development in an Angular CLI project, you would modify the proxy.conf.json file. This file allows you to define proxy rules for routing requests to different backend servers, helping you bypass CORS restrictions.
In the Angular router, what is the purpose of the pathMatch property?
- It defines a regex pattern for matching route paths.
- It defines the route's path as an exact match.
- It determines the order in which routes are evaluated.
- It specifies the default route when no other route matches.
The 'pathMatch' property in Angular router configurations is used to define how the router should match the URL path. When set to 'full', it requires an exact match of the path segment, ensuring that the URL path must match the route path entirely for the route to activate. This is useful for defining routes with empty path or catch-all routes.
What is the primary command to create a new Angular application using Angular CLI?
- ng create
- ng generate
- ng init
- ng new
The primary command to create a new Angular application using Angular CLI is ng new. This command initializes a new Angular project with default settings, including the necessary files and folder structure.
Which header is crucial for making a CORS request to a different domain using HttpClient?
- 'Access-Control-Allow-Origin'
- 'Authorization'
- 'Content-Type'
- 'User-Agent'
The 'Access-Control-Allow-Origin' header is crucial for enabling Cross-Origin Resource Sharing (CORS) when making requests to a different domain. It specifies which origins are permitted to access the requested resource, allowing for secure cross-domain communication.
The tick function is provided by the ______ testing utility to simulate the passage of time in tests.
- ComponentFixture
- TestBed
- fakeAsync
- tick
The fakeAsync testing utility in Angular provides the tick function. It allows you to simulate the passage of time in a test, particularly useful for testing asynchronous operations like timers and HTTP requests.
What is the main drawback of using the default change detection strategy in larger applications?
- Difficulty in handling component state.
- Incompatibility with Angular CLI.
- Limited support for unit testing.
- Slower performance due to frequent view checks.
The primary drawback of using the default change detection strategy in larger Angular applications is slower performance. This is because the default strategy involves frequent checks of the entire component tree, which can become a performance bottleneck as the application grows. Developers may need to switch to alternative strategies like OnPush to mitigate this issue.
In template-driven forms, the ______ directive is used to group controls and aggregate their values and validation status.
- FormGroupDirective
- NgModelGroupDirective
- FormControlDirective
- FormsModuleDirective
In template-driven forms in Angular, the NgModelGroupDirective is used to group controls and aggregate their values and validation status. This directive allows you to manage the behavior and validation of a group of form controls within a form. The other options are not used for this purpose in template-driven forms.
How can a child component emit an event to inform its parent component about a particular action?
- By calling a predefined Angular function, emitEvent(), from the child component.
- By modifying the parent component's properties directly from the child component.
- By using @Output and emitting an event from the child component, which the parent component can listen to.
- By using Angular services to communicate between the child and parent components.
A child component can emit an event to inform its parent component by using @Output and emitting an event that the parent component can subscribe to. Directly modifying the parent component's properties from the child component is not a recommended practice. Calling a predefined function like emitEvent() is not a standard Angular approach. Using services can facilitate communication between components but is not the direct way for a child to inform its parent about an action.
Which directive is used in template-driven forms to track the state and validity of form controls?
- [formGroup]
- [formControl]
- [ngModel]
- [formStatus]
In template-driven forms, the [ngModel] directive is used to track the state and validity of form controls. It allows you to access information about the control's state, such as whether it's valid, touched, or dirty. This is crucial for implementing form validation and displaying error messages based on the control's state. The other options, [formGroup] and [formControl], are typically used in reactive forms.