【发布时间】:2022-08-18 15:59:10
【问题描述】:
我的问题是表数据没有打印,我认为我的问题出在我的数据源上,我不知道我必须以什么方式修复它。我将分享我的模型和相关代码来解决这个问题。 这是我的模型
export class HubxModel{
id: number;
categoryId: number;
itemTitle: string;
itemUnit: string;
isActive: boolean=true;
itemValue: string;
patientId: number;
isDeleted: boolean;
}
下面的代码是我如何定义我的数据源
export class UserPatientsReportFormComponent implements OnInit {
displayedColumns: string[] = [\'itemTitle\', \'itemValue\', \'itemUnit\'];
hubxReportList : Array<HubxDataModel> = [];
下面的代码是我的 html 部分
<div class=\"row paddingTop headerpaddingbottom\" >
<section class=\"col-sm-8 example-container mat-elevation-z8\" tabindex=\"0\">
<table mat-table [dataSource]=\"hubxReportList \" class=\"col-sm-12\">
<ng-container matColumnDef=\"itemTitle\">
<th mat-header-cell *matHeaderCellDef> Test Name </th>
<td mat-cell *matCellDef=\"let element\"> {{element.itemTitle}} </td>
</ng-container>
<!-- value Column -->
<ng-container matColumnDef=\"itemValue\">
<th mat-header-cell *matHeaderCellDef> Result </th>
<td mat-cell *matCellDef=\"let element\"> {{element.itemValue}} </td>
</ng-container>
<!-- Unit Column -->
<ng-container matColumnDef=\"itemUnit\">
<th mat-header-cell *matHeaderCellDef> Unit </th>
<td mat-cell *matCellDef=\"let element\"> {{element.itemUnit}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef=\"displayedColumns; sticky: true\"></tr>
<tr mat-row *matRowDef=\"let row; columns: displayedColumns;\"></tr>
</table>
</section>
</div>
这就是我从 api 获取数据的方式
getHubxReport() {
//debugger
this.usersService.getHubxReport(this.clientId).subscribe((response: ResponseModel) => {
if (response != null && response.data != null && response.data.length > 0) {
this.hubxReportList = response.data;
}
}
);
}
-
创建一个 stackblitz 示例。图片不能很好地表达问题。
-
我认为我的问题在于数据源。任何想法我怎样才能使它正确。
-
看起来你的“数组”的属性不是你显示的属性,在你的订阅函数中使用
console.log(this.huxReportList)(我想变量在 PascalCase 而不是 CamelCase 或类似的) -
我添加了检查console.log(this.huxReportList)后得到的结果,请检查
标签: angular