Which method of ViewContainerRef allows you to insert a component?

  • createComponent()
  • deleteComponent()
  • updateComponent()
  • renderComponent()
The method of ViewContainerRef that allows you to insert a component is createComponent(). This method is used to create and insert a dynamic component into the specified view container. The other options are not valid methods of ViewContainerRef and do not serve the purpose of inserting components.

What is the main purpose of Angular's ngIf directive?

  • To create a new Angular component.
  • To conditionally show or hide elements.
  • To define a route in an Angular application.
  • To style Angular components.
The primary purpose of Angular's ngIf directive is to conditionally show or hide elements in the DOM based on a given condition. This is useful for displaying or hiding parts of a user interface depending on the application's state or user interactions. The other options do not accurately describe the main purpose of ngIf.

To update your Angular CLI globally to the latest version, you would use the command npm install -g ________.

  • @angular/cli
  • angular
  • ng
  • typescript
To update your Angular CLI globally to the latest version, you would use the command npm install -g @angular/cli. This command installs or updates the Angular CLI package globally, ensuring you have the latest version available.

The directive that's used to manipulate the structure of the DOM by adding/removing elements is prefixed with ________.

  • *ngFor
  • *ngIf
  • *ngSwitch
  • *ngStyle
The directive used to manipulate the DOM structure by adding or removing elements conditionally is prefixed with *ngIf in Angular. It allows you to control whether an element is rendered based on a given condition. The other options, like *ngFor, *ngSwitch, and *ngStyle, are used for different purposes in Angular and do not add or remove elements from the DOM.

What would you use to capture and act upon route parameters passed in a URL in Angular?

  • ActivatedRouteSnapshot and RouteParams
  • Router and ActivatedRoute
  • ActivatedRoute and Router
  • RouteData and RouteSnapshot
To capture and act upon route parameters in Angular, you would use ActivatedRouteSnapshot and RouteParams. These are part of the Angular Router and provide access to the parameters passed in the URL, allowing you to utilize them in your components. The other options may be components of the Angular Router, but they are not the primary tools for capturing and acting upon route parameters.

What is the primary difference between Observables and Promises?

  • Observables are only used for HTTP requests, while Promises are for other asynchronous tasks
  • Observables can handle multiple values over time, while Promises handle a single value
  • Promises are asynchronous, while Observables are synchronous
  • Promises are part of JavaScript, while Observables are part of Angular
The primary difference is that Observables can handle multiple values over time, while Promises handle a single value. Observables are often used for handling streams of data, such as events, real-time updates, or user input. Promises are better suited for handling a single asynchronous operation.

What should you do to ensure that an HTTP request is unsubscribed automatically when a component is destroyed?

  • Automatically unsubscribed by default
  • Manually unsubscribe in the ngOnDestroy lifecycle hook
  • Use the async pipe
  • Use the takeUntil() operator with a subject
To ensure that an HTTP request is unsubscribed automatically when a component is destroyed, you should use the 'takeUntil()' operator with a subject. This pattern helps prevent memory leaks by unsubscribing from observable streams when the component is no longer in use.

Which testing framework is primarily used alongside Angular for unit testing?

  • Jasmine
  • Jest
  • Mocha
  • Protractor
Jasmine is the most commonly used testing framework for unit testing in Angular applications. It provides a rich set of features for writing and running tests, including matchers for assertions and spies for tracking function calls.

Which command allows you to add a new capability, like Angular Material, to your Angular application using Angular CLI?

  • ng new
  • ng add
  • ng generate
  • ng install
To add a new capability or library to your Angular application, such as Angular Material, you can use the "ng add" command. This command not only installs the library but also performs any necessary configuration, making it a convenient way to enhance your project.

The ______ guard is used to decide if the current route can be deactivated.

  • CanActivate
  • CanActivateChild
  • CanDeactivate
  • CanLoad
In Angular, the CanDeactivate guard is used to decide if the current route can be deactivated. It's often used to prompt users for confirmation before leaving a page with unsaved changes.