You are building a component that fetches data from an API. However, you want to ensure that the component only triggers the API call when it's actually visible to the user. Which lifecycle hook can help you achieve this?

  • ngAfterViewInit Lifecycle Hook
  • ngDoCheck Lifecycle Hook
  • ngOnDestroy Lifecycle Hook
  • ngOnInit Lifecycle Hook
To ensure that the component triggers the API call when it's actually visible, you can use the ngAfterViewInit lifecycle hook, which is called after the component's view has been initialized.

In Angular, the method used to add a new form control to a FormArray dynamically is ____.

  • addFormControl
  • appendControl
  • createControl
  • pushControl
In Angular, the method used to add a new form control to a FormArray dynamically is appendControl. This method allows you to dynamically add a new form control to an existing FormArray.

To reactively listen to changes to route parameters in Angular, you should use the _____ property of the ActivatedRoute service.

  • paramMap
  • paramsChanged
  • routeChange
  • routeParams
To reactively listen to changes to route parameters in Angular, you should use the paramMap property of the ActivatedRoute service.

You need to create a custom directive that changes the background color of an element when the user hovers over it. What Angular concepts and decorators would you use to achieve this?

  • Apply styles directly in the component's HTML template
  • Implement ngOnChanges to track changes in the element's state
  • Use @HostListener to handle hover events
  • Utilize @ViewChild to access the element and manipulate its styles
To create a custom directive that changes the background color on hover, you would use the @HostListener decorator to handle hover events and apply the desired behavior.

In Jasmine, to ensure that an asynchronous operation has completed before continuing the test, you can use the _____ function.

  • afterEach()
  • spyOnAsync()
  • tick()
  • waitForAsync()
In Jasmine, to ensure that an asynchronous operation has completed before continuing the test, you can use the tick() function.

What is a potential consequence of not unsubscribing from an observable in an Angular component?

  • Better application responsiveness
  • Improved performance
  • Memory leaks
  • Reduced CPU usage
Not unsubscribing from an observable in an Angular component can lead to memory leaks, as the subscription remains open, causing resources to accumulate over time.

What is the purpose of the updateOn property when creating a new FormControl instance?

  • It defines the initial control value
  • It determines when the control is updated
  • It sets the control's required state
  • It specifies when to submit the form data
The updateOn property when creating a new FormControl instance in Angular specifies when the control is updated, which affects how and when the form data is updated and submitted.

How does the @HostListener decorator enhance the functionality of a directive?

  • Allows the directive to listen to events on the host element
  • Binds data to HTML elements
  • Defines component lifecycle hooks
  • Enables routing in directives
The @HostListener decorator in Angular allows the directive to listen to events on the host element, enhancing its interactivity and behavior.

Components that are designed to be reusable across multiple parts of an application often implement the _____ lifecycle hook to do cleanup work.

  • ngDoCheck
  • ngOnChanges
  • ngOnDestroy
  • ngOnInit
Components that are designed to be reusable across multiple parts of an application often implement the ngOnDestroy lifecycle hook to do cleanup work, like unsubscribing from observables.

The method used to add a new form control to an existing Form Array is _____ .

  • addControl
  • addFormControl
  • insertControl
  • pushControl
The method used to add a new form control to an existing Form Array is addControl.

What is the main purpose of using directives in Angular applications?

  • Create components
  • Define routing
  • Manipulate the DOM
  • Modify data
The main purpose of using directives in Angular applications is to manipulate the DOM by adding, removing, or modifying elements and their behavior. Directives are used to extend HTML with new attributes and elements.

When you want a component to render content into its template from outside, you use a _____.

  • Directive
  • Module
  • Pipe
  • Service
When you want a component to render content into its template from outside, you use a Directive.