angular/aio/content/blocks/core/switch.md
Pawel Kozlowski 6b3f0bd0ea docs: control flow API reference (#52397)
Adds API reference for the new built-in control flow.

PR Close #52397
2023-10-27 12:56:51 -07:00

701 B

The @switch block is inspired by the JavaScript switch statement:

@syntax

@switch (condition) {
  @case (caseA) {
    Case A.
  }
  @case (caseB) {
    Case B.
  }
  @default {
    Default case.
  }
}

@description

The @switch blocks displays content selected by one of the cases matching against the conditional expression. The value of the conditional expression is compared to the case expression using the === operator.

The @default block is optional and can be omitted. If no @case matches the expression and there is no @default block, nothing is shown.

@switch does not have fallthrough, so you do not need an equivalent to a break or return statement.