61 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
 | 
						|
p.location-badge.
 | 
						|
  exported from <a href="/angular2/directives.html">angular2/directives</a>
 | 
						|
  defined in <a href="https://github.com/angular/angular/tree/master/modules/angular2/src/directives/switch.js#L39">angular2/src/directives/switch.js (line 39)</a>
 | 
						|
 | 
						|
:markdown
 | 
						|
  The `Switch` directive is used to conditionally swap DOM structure on your template based on a
 | 
						|
  scope expression.
 | 
						|
  Elements within `Switch` but without `SwitchWhen` or `SwitchDefault` directives will be
 | 
						|
  preserved at the location as specified in the template.
 | 
						|
  
 | 
						|
  `Switch` simply chooses nested elements and makes them visible based on which element matches
 | 
						|
  the value obtained from the evaluated expression. In other words, you define a container element
 | 
						|
  (where you place the directive), place an expression on the **`[switch]="..."` attribute**),
 | 
						|
  define any inner elements inside of the directive and place a `[switch-when]` attribute per
 | 
						|
  element.
 | 
						|
  The when attribute is used to inform Switch which element to display when the expression is
 | 
						|
  evaluated. If a matching expression is not found via a when attribute then an element with the
 | 
						|
  default attribute is displayed.
 | 
						|
  
 | 
						|
  # Example:
 | 
						|
  
 | 
						|
  ```
 | 
						|
  <ANY [switch]="expression">
 | 
						|
    <template [switch-when]="whenExpression1">...</template>
 | 
						|
    <template [switch-when]="whenExpression1">...</template>
 | 
						|
    <template [switch-default]>...</template>
 | 
						|
  </ANY>
 | 
						|
  ```
 | 
						|
  
 | 
						|
.l-main-section
 | 
						|
  h2 Members
 | 
						|
  .l-sub-section
 | 
						|
    h3 constructor
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        constructor()
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  .l-sub-section
 | 
						|
    h3 value
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        value(value)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |