Bird
0
0

You want to create a computed signal that returns the full address from multiple signals: street, city, and zip. Which code correctly implements this?

hard📝 component behavior Q8 of 15
Angular - Signals
You want to create a computed signal that returns the full address from multiple signals: street, city, and zip. Which code correctly implements this?
Aconst fullAddress = computed(street() + city() + zip());
Bconst fullAddress = computed(() => street + city + zip);
Cconst fullAddress = signal(() => `${street()} ${city()} ${zip()}`);
Dconst fullAddress = computed(() => `${street()} ${city()} ${zip()}`);
Step-by-Step Solution
Solution:
  1. Step 1: Use computed with a function returning combined string

    The computed signal must be created with a function that calls each signal to get current values.
  2. Step 2: Check each option for correct syntax

    const fullAddress = computed(() => `${street()} ${city()} ${zip()}`); correctly uses computed with a template string and calls each signal. Others misuse signal or omit function calls.
  3. Final Answer:

    const fullAddress = computed(() => `${street()} ${city()} ${zip()}`); -> Option D
  4. Quick Check:

    Combine signals inside computed with calls and template string [OK]
Quick Trick: Use computed with () calls and template strings for combined values [OK]
Common Mistakes:
  • Concatenating signals without calling them
  • Using signal() instead of computed() for derived values
  • Passing computed argument without a function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes