Bird
0
0

You want to create a pipe that formats a date string to 'YYYY-MM-DD' but only if the input is a valid date. How should you handle invalid inputs in your custom pipe?

hard📝 component behavior Q8 of 15
Angular - Pipes
You want to create a pipe that formats a date string to 'YYYY-MM-DD' but only if the input is a valid date. How should you handle invalid inputs in your custom pipe?
AReturn the original input unchanged
BThrow an error to stop rendering
CReturn an empty string
DReturn null
Step-by-Step Solution
Solution:
  1. Step 1: Consider user experience for invalid input

    Throwing errors or returning null can break the UI or cause unexpected behavior.
  2. Step 2: Choose safe fallback

    Returning the original input unchanged is safe and lets the UI show raw data if invalid.
  3. Final Answer:

    Return the original input unchanged -> Option A
  4. Quick Check:

    Handle invalid input safely by returning original [OK]
Quick Trick: Return original input if invalid to avoid errors [OK]
Common Mistakes:
  • Throwing errors inside pipes
  • Returning null causing blank UI
  • Returning empty string hiding data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes