Bird
0
0

Given this Angular template snippet:

medium📝 state output Q13 of 15
Angular - HTTP Client
Given this Angular template snippet:
<div *ngIf="error()" role="alert">Error: {{ error() }}</div>
<div *ngIf="isLoading()">Loading...</div>
<div *ngIf="!isLoading() && !error()">Data loaded</div>

What will be displayed if isLoading() returns false and error() returns "Network error"?
ALoading...
BError: Network error
CData loaded
DNothing is displayed
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate conditions with given values

    isLoading() is false, error() is "Network error" (truthy).
  2. Step 2: Check which *ngIf blocks show

    The first div shows if error() is truthy, so it displays "Error: Network error". The second div shows if isLoading() is true (false here), so no. The third div shows if not loading and no error, but error exists, so no.
  3. Final Answer:

    Error: Network error -> Option B
  4. Quick Check:

    Error present = show error message [OK]
Quick Trick: Error message shows if error() is truthy, regardless of loading [OK]
Common Mistakes:
MISTAKES
  • Ignoring error() and showing loading
  • Showing data loaded despite error
  • Assuming nothing shows when error exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes