Thank you in advance for your attention.
I'm having trouble popularizing an object list returned from an API in Angular 7. My service class is returning service data, however I can not popular in my object list (returned from service). Below is the details of my implementation.
Json
{
"sucess":true,
"message":"Sucesso",
"data":[
{
"codigoPlanoContratacao":"DGC1",
"codigoCobertura":223,
"descricaoCobertura":"ASSISTENCIA DOMICILIAR II",
"codigoTipoRisco":0,
"valorImportanciaSegurada":0,
"valorPremioLiquido":24.0
},
{
"codigoPlanoContratacao":"DGC1",
"codigoCobertura":400,
"descricaoCobertura":"INC./RAIO/EXPL./QUEDA AERONAVE",
"codigoTipoRisco":0,
"valorImportanciaSegurada":50000,
"valorPremioLiquido":26.25
},
{
"codigoPlanoContratacao":"DGC1",
"codigoCobertura":404,
"descricaoCobertura":"VENDAVAL/IMPACTO VEICULO",
"codigoTipoRisco":0,
"valorImportanciaSegurada":10000,
"valorPremioLiquido":31.09
}]
}
My service.ts
TodasCoberturas() : Coberturas[] {
this.http.get<Coberturas[]>(this.UrlServiceV1 + "combinadoPlano?codigoTipoRisco=1")
.subscribe(
data => {
debugger;
this.coberturas = data;
});
return this.coberturas;
}
Coverage Class
export class Coberturas{
codigoPlanoContratacao: string
codigoCobertura: number
descricaoCobertura: string
codigoTipoRisco: number
valorImportanciaSegurada: number
valorPremioLiquido: number
}
componenet.ts
public coberturas: Coberturas[];
constructor(public coberturasServices: CoberturasServices) {
this.coberturas = this.coberturasServices.retornarListaDetalhe();
}
html
Butindebugger,Icanviewmyobjectlist,howeverIcannotseemtobepopularinmyvariable.IalreadytriedtoperformaforaddingobjectstothereturneddataandIwasnotsuccessful,sinceitinformsthatmyvariableisundefined.
Thanks again.