Skip to main content

Posts

Showing posts with the label track by

What Is trackBy in Angular? | When to Use in ngFor and ng-repeat?

The “ track by ” expression to specify unique keys.   The “ track by ” takes a function that has two arguments: index and item. If “track by” is given, Angular tracks changes by the return value of the function. Understanding About *ngFor Mechanisms:- By default, when you use * ngFor without “track by”, *ngFor tracks array of objects changing through object identity. If you are going to modify (add, update, remove) any element of * ngFor , then update the tracking algorithm by providing your object id to the “track by”function.” Why use “track by”with ngFor directive? The “ngFor” directive may perform poorly with large lists. A small change to the list like, adding a new item or removing an existing item may trigger several DOM manipulations. Syntax of ngFor Angular: < tr   *ngFor = "let user of users; let i = index" >      < td > {{user.name}} </ td >    ...

Error : [ngRepeat:dupes] duplicates in a repeater are not allowed.

Duplicates in a repeater are not allowed. Use ' track by ' expression to specify unique keys. Repeater: {0}, Duplicate key: {1}, Duplicate value: {2} By default, collections are keyed by reference which is desirable for most common models but can be problematic for primitive types that are interned. My Problem is - Error: [ngRepeat:dupes] duplicates in a repeater are not allowed. // this code throws the error "Duplicates in a repeater are not allowed. // ngRepeater: row in ['Declined By P', 'Quoted By P', 'Quoted By P', 'Declined By P', 'Declined By P']" < ul >   < li ng-repeat = "row in ['Declined By P', 'Quoted By P', 'Quoted By P', 'Declined By P', 'Declined By P']" >       {{row}}   </ li > </ ul > AngularJs does not allow duplicates in ng-repeat directive . So I got an error - ngRepeat:dupes The Solution is - Use ...