To apply styles scoped to a particular component and prevent them from affecting other elements outside the component, you would use _____.
- ::ng-deep
- ViewEncapsulation.Emulated
- ViewEncapsulation.None
- ng-deep
To apply styles scoped to a particular component in Angular and prevent them from leaking out and affecting other elements, you would use the ::ng-deep selector. This is used to pierce through the view encapsulation and apply styles to specific components.
For handling multiple values over time in Angular, you would use ________ instead of Promises.
- Components
- Decorators
- Modules
- Observables
In Angular, when you need to handle multiple values over time, you should use Observables instead of Promises. Observables are more versatile and allow you to work with asynchronous data in a more flexible manner. They can emit multiple values, making them ideal for scenarios like handling streams of data from HTTP requests or user interactions.
What is the primary use of in Angular?
- To define a new component in Angular.
- To display data from an API.
- To project content from a parent component into a child component.
- To style Angular components using CSS.
The primary use of in Angular is to project content from a parent component into a child component. This allows you to pass content or HTML elements from a parent component to a designated location in a child component, facilitating component reusability and flexibility. It's a fundamental concept in Angular for creating dynamic and customizable components.
To project specific content into a designated slot, you would use the select attribute of with a ________ selector.
- Class
- Slot
- Name
- Tag
When using content projection in Angular with , you typically use the select attribute with a CSS class selector to specify where the content should be projected. This allows you to target specific slots in the child component's template. Options 1, 3, and 4 are not commonly used in this context.
Which module should you import to use the HttpClient in an Angular application?
- @angular/common/http
- @angular/core
- @angular/forms
- @angular/router
To use the HttpClient in an Angular application, you should import the @angular/common/http module. This module provides the HttpClient service for making HTTP requests.
A client asks for a feature where a child component should be able to inform its parent component when a button inside the child component is clicked. How would you implement this interaction?
- Use the @Output decorator to emit an event from the child component and bind to it in the parent component.
- Use the @ViewChild decorator to access the child component's method directly from the parent component.
- Use the @Input decorator to pass a callback function from the parent to the child component.
- Use the @HostListener decorator to listen for events in the child component and trigger a method in the parent component.
To implement communication from child to parent in Angular, you can use the @Output decorator to emit an event from the child component, and the parent component can bind to this event to listen for changes. This allows the child to inform the parent when the button is clicked. The other options are not the typical approach for this scenario.
In Angular's reactive forms, the method used to mark a control as touched is called ______.
- markAsDirty()
- markAsTouched()
- setDirty()
- setTouched()
In Angular's reactive forms, the method used to mark a control as touched is called markAsTouched(). This method is used to indicate that a form control has been interacted with by the user. It's commonly used for validation and to show error messages for untouched controls.
When creating a custom form control in Angular, which interface should it implement to work seamlessly with Angular's form directives?
- ControlValueAccessor
- FormControl
- FormGroup
- FormControlDirective
When creating a custom form control in Angular, it should implement the ControlValueAccessor interface to work seamlessly with Angular's form directives. This interface provides methods for connecting custom form controls with Angular's forms API, enabling the control to interact correctly with form directives like ngModel, formControl, and formGroup. The other options (FormControl, FormGroup, FormControlDirective) are related to form handling but do not specifically enable custom form control integration.
In Jasmine, which function is used to create spies that can track calls, arguments, and return values?
- createSpy
- spyOn
- trackSpy
- watchSpy
In Jasmine, the spyOn function is used to create spies. Spies are functions that can replace existing functions or be standalone, and they allow you to track function calls, arguments passed to them, and even control their behavior, including returning specific values.
Which is NOT a lifecycle hook in Angular?
- ngOnInit
- ngRender
- ngAfterViewInit
- ngOnDestroy
ngRender is not a standard lifecycle hook in Angular. The other options (ngOnInit, ngAfterViewInit, ngOnDestroy) are all valid Angular lifecycle hooks. These hooks allow developers to tap into various stages of a component's lifecycle to perform actions like initialization, cleanup, and interaction with the DOM. Understanding these hooks is crucial for managing component behavior and interactions in Angular applications.