Angular does not display API data

Asked

Viewed 40 times

-2

I’m building an . net core API using c# with visual studio 2019. the entities are publisher and book and testing via Swagger and Postman, the CRUD of both is working perfectly.

However, I started the implementation using the angular to consume this API and that’s where I’m having problems.

In the book register, there is a "dropdownlist" where the registered publishers should appear to link to the new book that will be registered, but this list is not being displayed and I have no idea why. Just like listing the books already registered, nothing appears, and there are records in the database and everything works perfectly running directly in the API. Below snippet of the code where the error is happening.

This whole project I went up to a repository on Github, follow the link: https://github.com/LDiegoDev/API-Biblioteca

      <div class="form-group">
<label class="control-label" for="EditoraId">Editora</label>
<select class="form-control" data-val="true" formControlName="editoraId"
  data-val-required="O campo Editora é obrigatório" id="EditoraId" name="EditoraId">
  <option></option>
  <option *ngFor='let editora of editoras' value="{{ editora.id }}">{{ editora.nome }}</option>
</select>

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor 
only supports binding to Iterables such as Arrays. at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck
 (common.js:3368) at checkAndUpdateDirectiveInline (core.js:22102) at checkAndUpdateNodeInline (core.js:23363) at checkAndUpdateNode (core.js:23325) 
at debugCheckAndUpdateNode (core.js:23959) at debugCheckDirectivesFn (core.js:23919) at Object.eval [as updateDirectives] (ListaComponent.html:23) 
at Object.debugUpdateDirectives [as updateDirectives] (core.js:23911) at checkAndUpdateView (core.js:23307) at callViewAction (core.js:23548) 
View_ListaComponent_0 @ ListaComponent.html:8 ListaComponent.html:8 ERROR CONTEXT DebugContext_

1 answer

0

Check what is populating your variable editoras. If you are returning an object, and not one array you can convert to an array using Object.values

Browser other questions tagged

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