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.
In Jasmine, the ______ function is used to define expectations for a test.
- beforeEach
- describe
- expect
- it
In Jasmine, the expect function is used to define expectations (assertions) for a test. It is used within an it block to specify what should happen during the test and what should be verified as correct behavior.
When using , which lifecycle hook is ideal for accessing projected content inside the child component?
- ngAfterContentInit()
- ngAfterViewInit()
- ngOnChanges()
- ngOnInit()
When using , the ideal lifecycle hook for accessing projected content inside the child component is ngAfterContentInit(). This hook is triggered after content projection has taken place, allowing you to work with the projected content effectively. ngOnInit() is too early in the component lifecycle, and ngOnChanges() and ngAfterViewInit() are not specifically related to content projection.
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.
When you want to disable a form control conditionally based on some logic, you would use the ______ attribute.
- [conditionalControlDisable]
- [controlToggle]
- [disable]
- [ngControlDisabled]
When you want to disable a form control conditionally based on some logic in Angular template-driven forms, you would use the [disable] attribute. This attribute allows you to bind a condition to the disabled state of a form control, making it either enabled or disabled based on the provided logic. It's a crucial feature for creating dynamic and responsive forms.