how to use track by inside ngFor angular 2

前端 未结 5 1727
天命终不由人
天命终不由人 2020-11-28 11:59

tried every syntax i can guess couldnt make it works !



{{post|json}}
         


        
5条回答
  •  佛祖请我去吃肉
    2020-11-28 12:24

    The concept behind trackBy:

    1. ngFor of angular automatically optimizes the display of modified/created/deleted objects by tracking through object identity. So, if you create all new objects in the list and then use ngFor, it will render whole list.

    2. Let's consider a scenario where despite of all ngFor optimizations, the rendering is still taking time. In that case we use trackBy. So that, we can provide another parameter to track objects than the object identity which is a default tracking criteria.

    A running example:

    
    
    
    
        Angular 2.1.2 + TypeScript Starter Kit
        
        
    
        
        
        
        
        
      
    
    
    
        
            loading...
        
    
    
    
    

提交回复
热议问题