Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trackByIndex(index: number, obj: any): any {
- return index;
- }
- <div *ngFor="let comment of comments; let i = index; trackBy: trackByIndex">
- {{ i, comment.text }}
- <div *ngFor="let answer of comment.answers; let j = index; trackBy: trackByIndex">{{ j, answer.text }}</div>
- </div>
- "comment 1": {
- "answer 1",
- "answer 2"
- },
- "comment 2": {
- "answer 1", // должен быть индекс 3
- "answer 2" // должен быть индекс 4
- }
- <div *ngFor="let comment of comments; let i = index; trackBy: trackByIndex">
- {{ i, comment.text }}
- <div *ngFor="let answer of comment.answers; let j = index; trackBy: trackByIndex">{{ answer.text }} {{counter++}}</div>
- </div>
- counter: number = 0;
- import { Component } from "@angular/core";
- @Component({
- selector: "app-root",
- template: `
- <ul class="nth-reset">
- <li *ngFor="let x of data; let i = index">
- Section {{i+1}}
- <ul>
- <li *ngFor="let y of x" class="nth-inc">
- {{y}} is item #<span class="nth"></span>
- </li>
- </ul>
- </li>
- </ul>
- `,
- styles: [`
- .nth-reset { counter-reset: nth 0 }
- .nth-inc {counter-increment: nth }
- .nth:after { content: counter(nth) }
- `]
- })
- export class AppComponent {
- data = [
- ["1-A", "1-B", "1-C"],
- ["2-A", "2-B"],
- ["3-A", "3-B", "3-C", "3-D"]
- ];
- }
Add Comment
Please, Sign In to add comment