I have a object named DTA
, in this object, I have an array named PTF_DTA
.
Then, I want to display the EXERCICE
variable.
Here is the JSON.
I have an error message =>
TS2339: Property 'EXERCICE' does not exist on type 'PortefeuilleDta[]'.
I don't understand how to solve this problem.
file.response.ts
export interface SearchDtaResponse extends ApiResponse {
DTA: Dta;
}
export interface Dta {
PP: PersonnePhysiqueDta;
PTF_DTA: PortefeuilleDta[];
}
export interface PortefeuilleDta {
DTA: {
PAYS: number;
EXERCICE: number;
STATUTDTA: number;
NUMEROSUIVI: number;
STATUTDTA_LIB: string;
}
PTF: {
REFERENCE: string;
INTITULE1: string;
COIN_LABEL: string;
ACTIF_LABEL: string;
ACTIF: number;
}
QUALITE: number;
QUALITE_LIB: string;
}
export interface PersonnePhysiqueDta {
NOMFAMILLE: string;
NUMEROREGISTRENATIONAL: number;
NATIONALITE: string;
PRENOM: string;
LIEUNAISSANCE: string;
DATENAISSANCE: Date;
PAYSDOMICILE: string;
}
HTML
<ng-container *ngIf="dta && dta.PP && dta.PTF_DTA">
<div style="width: 60%">
<div >
<div >
<div >
<table >
<tbody>
<ng-container>
<tr>
<th>Year</th>
<td> {{ dta.PTF_DTA.EXERCICE }} </td>
</tr>
<tr>
<th>Registre national</th>
<td>{{ dta.PP.NUMEROREGISTRENATIONAL}}</td>
</tr>
</ng-container>
</tbody>
</table>
</div>
</div>
</div>
</div>
</ng-container>
CodePudding user response:
I'm assuming the array is always length one, and the information is at the 0
index:
<td> {{ dta.PTF_DTA[0].DTA.EXERCICE }} </td>