Typeerror: list.map is not a Function

Asked

Viewed 456 times

1

I get the error described in the title in this situation:

carregarCategorias() {
    this.itemService.listarCategorias().then(lista => {
      this.categorias = lista.map(categoria => ({ label: categoria.descricao, value: categoria.id }));
    })
    .catch(erro => this.errorHandler.handle(erro));
  }

Does anyone have any tips ?

  • It means that lista is not a array. You can easily confirm what is doing console.log(typeof lista, lista) within the Promise

  • The search method used in the service is this : listCategories(): Promise<Category[]> { Return this.http.get<Category[]>(this.categoriesUrl). toPromise(); } return ai is not an array ?

  • Thanks for the tip, really the return was a Page<> and not a list so the map does not work. Vlw

No answers

Browser other questions tagged

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