122 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			122 lines
		
	
	
		
			2.1 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/for.js#L44">angular2/src/directives/for.js (line 44)</a>
 | 
						|
 | 
						|
:markdown
 | 
						|
  The `For` directive instantiates a template once per item from an iterable. The context for each
 | 
						|
  instantiated template inherits from the outer context with the given loop variable set to the
 | 
						|
  current item from the iterable.
 | 
						|
  
 | 
						|
  It is possible to alias the `index` to a local variable that will be set to the current loop
 | 
						|
  iteration in the template context.
 | 
						|
  
 | 
						|
  When the contents of the iterator changes, `For` makes the corresponding changes to the DOM:
 | 
						|
  
 | 
						|
  * When an item is added, a new instance of the template is added to the DOM.
 | 
						|
  * When an item is removed, its template instance is removed from the DOM.
 | 
						|
  * When items are reordered, their respective templates are reordered in the DOM.
 | 
						|
  
 | 
						|
  # Example
 | 
						|
  
 | 
						|
  ```
 | 
						|
  <ul>
 | 
						|
    <li *for="#error in errors; #i = index">
 | 
						|
      Error {{i}} of {{errors.length}}: {{error.message}}
 | 
						|
    </li>
 | 
						|
  </ul>
 | 
						|
  ```
 | 
						|
  
 | 
						|
  # Syntax
 | 
						|
  
 | 
						|
  - `<li *for="#item of items; #i = index">...</li>`
 | 
						|
  - `<li template="for #item of items; #i=index">...</li>`
 | 
						|
  - `<template [for]="#item" [of]="items" #i="index"><li>...</li></template>`
 | 
						|
  
 | 
						|
.l-main-section
 | 
						|
  h2 Members
 | 
						|
  .l-sub-section
 | 
						|
    h3 constructor
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        constructor(viewContainer:ViewContainer)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  .l-sub-section
 | 
						|
    h3 bulkInsert
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        bulkInsert(tuples, viewContainer)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  .l-sub-section
 | 
						|
    h3 bulkRemove
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        bulkRemove(tuples, viewContainer)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  .l-sub-section
 | 
						|
    h3 iterableChanges
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        iterableChanges(changes)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  .l-sub-section
 | 
						|
    h3 perViewChange
 | 
						|
 | 
						|
    
 | 
						|
    pre.prettyprint
 | 
						|
      code.
 | 
						|
        perViewChange(view, record)
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
  .l-sub-section
 | 
						|
    h3 viewContainer
 | 
						|
 | 
						|
    
 | 
						|
    :markdown
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 |