Popular table at angle 8

Asked

Viewed 297 times

1

Good morning,

I am trying to popular a table on my system, because the backend done in spring sends me a JSON as follows, an object with several lists inside, example:

{
"contasDespesasQuitadas": [
],
"contasDespesasAbertas": [
],
"contasReceitasQuitadas": [
],
"contasReceitasAbertas": [
]}

On TS, I try to popular the table in the following way:

filtrarDatas() {
if (this.dataInicial && this.dataFinal) {
  this.resultadoService.resultByPeriodFinal(this.dataInicial,this.dataFinal)
      .subscribe(res => {
       this.popularTabelaReceitaAberta(res.contasReceitasAbertas);
       this.totalReceitaAberta();

       this.popularTabelaReceitaQuitada(res.contasReceitasQuitadas);
       this.totalReceitaQuitada();

       this.popularTabelaDespesaAberta(res.contasDespesasAbertas);
       this.totalDespesaAberta();

       this.popularTabelaDespesaQuitada(res.contasDespesasQuitadas);
       this.totalDespesaQuitada();
  });
}

In the system the table is populated correctly, but the IDE displays an error message:

Property 'countsReceitasAbertas' does not exist on type 'any[]'

This happens in all tables, the error appears after I put "res.accountsReceitsBooks".

1 answer

1


This is common in Angular due to the data typing of Typescript, as in your code for example, when you make the following statement:

(res.contasReceitasAbertas)

You stated res but Typescript does not know if it can assign tell a res, exactly by typing. To get around this just type the variable res with the type any for example:

.subscribe((res: any) => {

That the error should not happen anymore. If you can give a read in this article that explains a lot there.

  • It worked by using ". subscribe((res: any) => {"

  • Cool man, success there!

  • 1

    thanks, success too.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.