Return to site
🅰️1️⃣7️⃣ Which of the following is a valid way to write a @switch block in Angular 17?
🅰️1️⃣7️⃣ Which of the following is a valid way to write a @switch block in Angular 17?
·
A) @switch (color) { @case (red) { <p>Red</p> } @case (green) { <p>Green</p> } @case (blue) { <p>Blue</p> } } B) @switch (color) { @case (red): <p>Red</p> @case (green): <p>Green</p> @case (blue): <p>Blue</p> } C) @switch (color) { @case (red) { <p>Red</p> } @case (green) { <p>Green</p> } @default { <p>Unknown</p> } } D) @switch (color) { @case (red) <p>Red</p> @case (green) <p>Green</p> @default <p>Unknown</p> }
#angular #angular17 #switch #newSyntax #frontend
https://lnkd.in/gyFq52hb
The correct answer is C. The @switch block in Angular 17 requires curly braces around each case and default block, and uses the @default keyword to specify the default case³. The other options are either missing the curly braces, the @default keyword, or using a colon instead of a curly brace.