html - 从 api 调用数据并且不显示在前置表上,但它在控制台上以角度显示
问题描述
从 API 获取的数据没有显示在屏幕上,但我正在控制台中获取数据。
这是 .ts 文件。
export class VisibilityComponent implements OnInit {
check = false;
pmDetails1: IEmployee[];
constructor( private userService: UserService) {
this.pmDetails1 = [];
}
ngOnInit() {
this.userService.getAllEmployee().subscribe((pmDetails1: IEmployee[]) => {
this.pmDetails1 = pmDetails1;
console.log(this.pmDetails1);
});
}
onItemChange(value) {
if (value === '1' ) {
this.check = true;
} else {
this.check = false;
}
}
}
<div>
<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.id }}"
[checked]="check"
/>
</td>
<td>{{p.name}}</td>
<td>{{p.role}}</td>
</tr>
</tbody>
</table>
</div>
这是控制台上的输出
请帮我解决这个问题。
解决方案
您的数据不包含元素id
和。name
role
相反,它有employeeId
,employeeName
和employeeRole
。您需要更新您的表代码。
<td>
<input
type="checkbox"
value="{{ p.employeeId }}"
[checked]="check"
/>
</td>
<td>{{p.employeeName}}</td>
<td>{{p.employeeRole}}</td>
推荐阅读
- c# - 扫射目标时如何让特工面对行进方向?(统一/C#)
- fonts - -sSUBSTFONT、-sCIDFSubstFont、-sCIDFSubstPath 不替换 PDF 字体
- javascript - 在 JavaScript ES6 中重新创建 SQL 查询
- react-native - React Native Expo Flatlist:为什么滚动不会在我移开手指的地方停止?
- javascript - 获取“未捕获的 TypeError:无法读取属性 'addEventListener' of null”
- css - 如何防止我的标题布局在 Squarespace 中悬停时移动?
- python - (TypeError: dtype complex128的图像数据不能转换为float)问题
- javascript - 使用 Bootstrap 重叠图像和文本 HTML 的问题
- r - 用R制作二维矢量图
- rust - 为什么我不必声明 x 对于仿射语义和函数类型是可重用/可复制的?