Bird
0
0

You want to optimize your Angular Universal app by sharing a list of products fetched on the server with the client using TransferState. Which approach correctly implements this?

hard📝 Application Q15 of 15
Angular - Server-Side Rendering
You want to optimize your Angular Universal app by sharing a list of products fetched on the server with the client using TransferState. Which approach correctly implements this?
AOn client, set products in TransferState and then fetch from server.
BOn client, always fetch products via HTTP and ignore TransferState.
COn server, store products in a global variable and access it directly on client.
DOn server, fetch products and call <code>transferState.set(PRODUCTS_KEY, products)</code>. On client, retrieve with <code>transferState.get(PRODUCTS_KEY, [])</code> before making HTTP call.
Step-by-Step Solution
Solution:
  1. Step 1: Understand TransferState usage for server-client data sharing

    Data fetched on server should be stored in TransferState to avoid client refetch.
  2. Step 2: Apply correct flow

    On server, fetch products and call transferState.set(PRODUCTS_KEY, products). On client, retrieve with transferState.get(PRODUCTS_KEY, []) before making HTTP call. correctly sets data on server and retrieves on client before HTTP call, optimizing performance.
  3. Step 3: Eliminate incorrect options

    Options B, C, and D misuse TransferState or data flow concepts.
  4. Final Answer:

    On server, fetch products and call transferState.set(PRODUCTS_KEY, products). On client, retrieve with transferState.get(PRODUCTS_KEY, []) before making HTTP call. -> Option D
  5. Quick Check:

    Server sets data, client gets data before HTTP [OK]
Quick Trick: Set on server, get on client before HTTP call [OK]
Common Mistakes:
  • Fetching data again on client ignoring TransferState
  • Trying to share data via global variables
  • Setting data on client instead of server

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes