【发布时间】:2021-06-04 14:22:31
【问题描述】:
我正在创建一个简单的 GET 请求,以列出来自 Angular / TypeScript 中的集成帐户的对象。以下是响应示例:
{
"value": [
{
"properties": {
"publicCertificate": "<publicCertificate>",
"createdTime": "2021-03-11T19:50:03.50193Z",
"changedTime": "2021-03-26T07:06:12.3232003Z"
},
"id": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/testResourceGroup/providers/Microsoft.Logic/integrationAccounts/testIntegrationAccount/certificates/<integrationAccountCertificateName>",
"name": "<integrationAccountCertificateName>",
"type": "Microsoft.Logic/integrationAccounts/certificates"
},
{
"properties": {
"publicCertificate": "<publicCertificate>",
"createdTime": "2021-05-27T12:45:33.455709Z",
"changedTime": "2021-05-27T12:45:33.4564322Z"
},
"id": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/testResourceGroup/providers/Microsoft.Logic/integrationAccounts/testIntegrationAccount/certificates/<integrationAccountCertificateName>",
"name": "<integrationAccountCertificateName>",
"type": "Microsoft.Logic/integrationAccounts/certificates"
}
]
}
这是我当前的界面
export interface Certificate {
value?: (ValueEntity)[] | null;
}
export interface ValueEntity {
properties: Properties;
id: string;
name: string;
type: string;
}
export interface Properties {
publicCertificate: string;
createdTime: string;
changedTime: string;
}
我只需要显示publicCertificate、id、name 和type 值。有没有更简单的方法来创建界面?
编辑
这是我目前使用的服务
@Injectable()
export class integrationAccountService
{
constructor(private httpclient: HttpClient, private api: ApiService) { }
getcertificates(): Observable<any> {
const httpOptions : Object = {
headers: new HttpHeaders({
'Authorization': 'Token'
}),
responseType: 'json'
};
return this.httpclient.get('URL', httpOptions);
}
}
组件
export class CertificateTableComponent {
dataSource: MatTableDataSource<ValueEntity>;
certificates: ValueEntity[] = [];
columns: string[] = ['name', 'id', 'type', 'publicCertificate'];
@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild(MatPaginator, { static:true }) paginator: MatPaginator;
constructor(private _integrationAccountService: integrationAccountService) {
}
ngOnInit() {
this._integrationAccountService.getcertificates().subscribe(response => {
this.certificates = response.data;
this.dataSource = new MatTableDataSource(this.certificates);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
})
}
}
显示数据的表格
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let row">{{ row.name }}</td>
</ng-container>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th>
<td mat-cell *matCellDef="let row">{{ row.id }}</td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Type</th>
<td mat-cell *matCellDef="let row">{{ row.type }}</td>
</ng-container>
<ng-container matColumnDef="publicCertificate">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Public Certificate</th>
<td mat-cell *matCellDef="let row">{{ row.publicCertificate }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columns"></tr>
<tr mat-row *matRowDef="let row; columns: columns;"></tr>
</table>
【问题讨论】:
-
请贴一些您之前尝试过的代码,有助于理解您的问题
-
我已经为服务、组件和表格添加了代码
标签: angular typescript