Angular 如何在另一个列表类型脚本中显示列表的元素
如何在Angular 如何在另一个列表类型脚本中显示列表的元素,angular,typescript,Angular,Typescript,如何在statusList1循环中显示statusList2中的元素 service.statusList1包含两个元素->[0],[1] <tr *ngFor="let status1 of service.statusList1; index as i"> <td>{{status1}}</td> <td>{{service.statusList2[i]}}</td> {{i+1}} &
statusList1
循环中显示statusList2
中的元素
service.statusList1
包含两个元素->[0],[1]
<tr *ngFor="let status1 of service.statusList1; index as i">
<td>{{status1}}</td>
<td>{{service.statusList2[i]}}</td>
{{i+1}}
</tr>
service.statusList2
包含两个元素->[0],[1]
<tr *ngFor="let status1 of service.statusList1; index as i">
<td>{{status1}}</td>
<td>{{service.statusList2[i]}}</td>
{{i+1}}
</tr>
{{status1}}
{{service.statusList2[i]}
{{i+1}}
我使用角度6
JavaScript旧学校是这样的:
for (let i = 0; i < someArray.length ; i++) {
let item = someArray[i];
}
for(设i=0;i
我想通过索引示例简单地描述角度6循环
<tr *ngFor="let status1 of service.statusList1; index as i">
<!-- <td>{{status1}}</td> -->
<td>{{service.statusList1[i]}}</td>
{{i+1}}
</tr>
{{service.statusList1[i]}
{{i+1}}
我确实创造了
如果有人可以编辑示例???您不需要“
Hello
”组件。休息似乎起作用了。我刚刚将app.component.ts
更改为:
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
array1: Array<string> = ["Hi","Hi2"];
array2: Array<any> = [{name: "No hi"},{name:"no hi2"}];
}
从'@angular/core'导入{Component};
@组成部分({
选择器:“我的应用程序”,
templateUrl:“./app.component.html”,
样式URL:['./app.component.css']
})
导出类AppComponent{
名称='角度';
array1:Array=[“Hi”,“Hi2”];
array2:Array是最新的Stackblitz这是一个非常简单的解决方案。只需使用let即可
<tr *ngFor="let a of arr1; let i = index">
<td>{{a.name}}</td>
<td>{{arr2[i].name}}</td>
</tr>
{{a.name}}
{{arr2[i].name}
正确的在这里
你能创建一个Stackblitz例子吗?在你上面的例子中,用let i=index
替换index as i
。这应该足够了。如果我使用let i=index,我是否需要删除{{i+1}?@Rajat@igg你是对的。请添加帖子给你一分+