How can you set default headers for every request made by HttpClient in your application?
- By adding headers to each HttpClient request manually
- By configuring HttpHeaders globally
- By modifying the HttpClient constructor
- By using an interceptor
You can set default headers for all HttpClient requests by using an interceptor. Interceptors allow you to intercept outgoing requests and modify them, including adding default headers, before they are sent.
Which of the following is the primary building block of an Angular application?
- Component
- Directive
- Module
- Service
In Angular, a component controls a patch of the screen called a view. Components are the main way to build and specify elements and logic on the page, making them the primary building block of an Angular application.
How can you set default values for form controls in a template-driven form?
- Use the defaultValue attribute.
- Assign values directly in the template.
- Set values programmatically in the component.
- Use the ngDefaultControl directive.
In template-driven forms, default values for form controls are typically set programmatically in the component by initializing the corresponding form control variables with the desired default values. While you can assign values directly in the template, this doesn't allow for dynamic default values or interaction with the component logic. The other options mentioned are not common practices for setting default values in template-driven forms.
What does the map operator in RxJS primarily do?
- Combines multiple Observables
- Filters data emitted by an Observable
- Subscribes to an Observable
- Transforms data emitted by an Observable
The map operator in RxJS primarily transforms data emitted by an Observable. It allows you to apply a function to each item emitted by the source Observable and returns a new Observable with the transformed values.
You are working on a large application where you need to display complex modal dialogs based on user interactions. How can dynamic components assist in this scenario?
- Dynamic components allow you to add styling to elements.
- Dynamic components can only be used in AngularJS.
- Dynamic components enable lazy loading of modules.
- Dynamic components can be created and rendered at runtime.
Dynamic components in Angular allow you to create and render components at runtime. This is particularly useful for displaying complex modal dialogs based on user interactions. You can dynamically load the modal component when needed, keeping the main application bundle smaller and improving performance. The other options do not accurately describe the capabilities of dynamic components.
To mock a service in Angular tests, you often replace the real service with a ______ service.
- Mock
- Spy
- Stub
- TestBed
In Angular testing, you typically replace the real service with a "Spy" service. A spy allows you to track calls to service methods, set up return values, and perform other testing-related tasks while avoiding actual service execution.
Which tag is used for multi-slot content projection in Angular?
The tag used for multi-slot content projection in Angular is . It allows you to project content into named slots within a component's template, providing a way to customize the rendering of components from their parent components. is used for defining templates, while and are not standard Angular tags for this purpose.
You have a requirement to build a complex multi-step form with the ability to navigate between steps and validate each step individually. What approach would you take in Angular to handle this?
- Creating separate components for each form step
- Implementing a custom form control for each step
- Using a single large form with form groups
- Utilizing the ngSwitch directive for step navigation
To build a complex multi-step form with navigation and individual step validation, it's advisable to create separate components for each form step in Angular. This approach promotes code modularity, makes step validation and navigation easier, and improves maintainability. Using a single large form with form groups can become unwieldy, and implementing custom form controls for each step might be overcomplicated. The ngSwitch directive is more for conditionally rendering content than for step navigation.
Which property in the Angular routes configuration is used to define lazy-loaded modules?
- component
- loadChildren
- pathMatch
- redirectTo
To define lazy-loaded modules in Angular routes, you use the loadChildren property in the route configuration. This property specifies the path to the module file that should be loaded lazily when the route is activated.
In state management, to listen to changes in a specific slice of the state tree, you'd use ________.
- Actions
- Middleware
- Reducers
- Selectors
In state management libraries like NgRx or Redux, Selectors are used to listen to changes in a specific slice of the state tree. Selectors allow you to extract and compute derived pieces of state efficiently. They are particularly helpful when you need to extract specific data from your state for presentation purposes or when a component should respond to changes in a specific part of the application state.