Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

@switch

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

See more...

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.