โ† All Angular Web Framework Flashcard Decks

Angular Advanced Practice Flashcards

7 cards from real Angular Web Framework practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Angular Advanced Practice flashcards as text
  1. In Angular's Router, what is the role of a `CanDeactivate` guard?

    Answer: Prevents leaving a route, useful for unsaved-changes warnings

    CanDeactivate lets you intercept an attempt to leave a route and prompt the user (e.g., 'You have unsaved changes, are you sure?') before allowing navigation away.

  2. Which lifecycle hook should you use to perform cleanup such as unsubscribing from Observables to prevent memory leaks?

    Answer: ngOnDestroy

    ngOnDestroy is called just before Angular destroys the component, making it the correct place to unsubscribe, clear timers, and release other resources.

  3. What does the `async` pipe do when it receives a new Observable or Promise?

    Answer: Unsubscribes from the old Observable and subscribes to the new one automatically

    When the bound reference changes, the async pipe unsubscribes from the previous stream and subscribes to the new one, always displaying the latest emitted value.

  4. Which Angular testing utility creates a synchronous test environment where you can interact with a compiled component?

    Answer: TestBed

    TestBed configures and compiles a test module that mimics an Angular module, allowing you to create component instances in an isolated test environment.

  5. In a reactive form, what class represents a group of form controls that can be validated as a unit?

    Answer: FormGroup

    FormGroup aggregates multiple FormControl instances into a single object, exposing the combined valid/invalid state and value as a plain JS object.

  6. What Angular schematic command generates a new lazy-loaded feature module with a routing file?

    Answer: ng generate module feature --routing --route feature

    The `--routing` flag adds a routing module, and `--route feature` registers the lazy-loaded route automatically in the parent router config.

  7. Which decorator is used to inject a dependency using a specific token rather than a class type?

    Answer: @Inject

    @Inject(TOKEN) explicitly tells Angular's DI system which injection token to resolve, necessary when the token is not a class (e.g., InjectionToken).