当我从 API 检索数据时,会显示“名字”和“姓氏”值。但“jobTitle”值未显示在表中,但它在控制台框中显示为数组。请帮我解决这个问题
这是visibility.ts文件:
export class VisibilityComponent implements OnInit {
pmDetails1: IEmployee[];
constructor(private userService: UserService) {}
ngOnInit() {
this.userService.getAllUsers().subscribe((pmDetails1: IEmployee[]) => {
this.pmDetails1 = pmDetails1;
console.log(pmDetails1);
console.log(pmDetails1[0].jobTitle);
});
}
}
这是 HTML 文件
<div>
<cdk-virtual-scroll-viewport itemSize="50" class="dialogbox-viewport">
<table class="table table-light" style="border: 1px solid">
<thead style="background-color: aqua">
<tr>
<th>Select</th>
<th>Name</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let p of pmDetails1">
<td>
<input type="checkbox" value="{{p.firstName}}" (change) = "onSelectedEmployee($event)" [checked]="check" />
</td>
<td>{{ p.firstName }} {{ p.lastName }}</td>
<td>{{ p.jobTitle }}</td>
</tr>
</tbody>
</table>
</cdk-virtual-scroll-viewport>
</div>
这是IEmployee.ts文件
export interface IEmployee {
userId: any;
firstName: string;
jobTitle: any;
lastName: String;
}
这是输出:
![在此输入图像描述][1]
这是“console.log(pmDetails1)”
![在此输入图像描述][2]
这是“console.log(pmDetails[0].jobTitles)”
我想在表的“角色”列中显示 jobTitlesName。我是 Angular 的初学者。请帮我做
慕田峪9158850
子衿沉夜
有只小跳蛙
相关分类