I have a recursive data structure (recursive via children
property) as below:
export interface IExecutableLog {
round: number;
log: string;
}
export interface IExecutableResult {
uid: string;
name: string;
desc: string;
status: string;
passedRounds: number;
totalRound: number;
children?: IExecutableResult[];
statementType?: string;
logs?: IExecutableLog[];
}
export interface ISummary {
title: string;
jobName: string;
timestamp: Date;
tester: string;
result: string;
executionId: string;
testJobId: string;
resultDetails: IExecutableResult;
}
And I want to display data of Isummary type from backend.
I tried define a component as below:
// pats-report-element.component.ts
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { IExecutableResult } from '../pats-report.interface';
@Component({
selector: 'pats-report-element',
templateUrl: 'app/report/basic/pats-report-element.html',
encapsulation: ViewEncapsulation.None,
})
export class PatsReportElementComponent {
@Input()
public data: IExecutableResult;
}
// app/report/basic/pats-report-element.html
<tr>
<td>{{data?.name}}</td>
<td>{{data?.status}}</td>
<td>{{data?.rounds}}</td>
<td>{{data?.passedRounds}}</td>
<td>{{data?.rounds > 0 ? (data.passedRounds / data.rounds) * 100 + "%" : "NA"}}</td>
<td>{{data?.timestamp | date:"y-MM-dd HH:mm:ss"}}</td>
</tr>
<template [ngIf]="data && data.children">
<template ngFor let-item [ngForOf]="data.children" let-i="index">
<pats-report-element [data]="item"></pats-report-element>
</template>
</template>
But the rendered DOM will include the host element 'pats-report-element' which is not valid inside a <table></table>
tag. The DOM is as below:
I checked the angular2 doc, and seems attribute-directives is the right choice. But I cannot find a way to use template with attribute-directives just like what I do in PatsReportElementComponent.
So what's the correct way to achieve my goal?
[Update 1]
Tried @Günter Zöchbauer's suggestion, still not resolve my issue. The rendered DOM is still not as expected (the <tr></tr>
still not being flattened).