【发布时间】:2021-02-24 13:20:28
【问题描述】:
我最近将一个项目从 Angular 8 更新到 Angular 10,但遇到了一些问题。我正在遍历两个单独的列表并显示数据
import { Component, Input } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<div *ngFor="let column of columns; let i of index">
Field: {{column['field']}}
<br>
Name: {{column['name']}}
<br>
Index: {{i}}
</div>`
})
export class AppComponent {
@Input() name: string;
columns: object[] = [
{field: 'FIELD_A', name:'NAME_A'},
{field: 'FIELD_B', name:'NAME_B'}
];
index: number[] = [0,1];
}
在 Angular 8 中,我的输出看起来像
Field: FIELD_A
Name: NAME_A
Index: [object Object]
Field: FIELD_B
Name: NAME_B
Index: [object Object]
在角度 10 中,我的输出看起来像
Field:
Name:
Index: 0
Field:
Name:
Index: 1
我的问题是:
- 为什么版本之间的这种行为不同?这是一个错误还是故意的?
- 为什么 Angular 8 将索引显示为对象?
请注意,将 let i of index 替换为 let i = index 会为两者提供正确一致的输出
Field: FIELD_A
Name: NAME_A
Index: 0
Field: FIELD_B
Name: NAME_B
Index: 1
【问题讨论】:
标签: angular typescript angular8