0

i'm trying to get Book data from Mysql with springBoot (BackEnd) and Angular(FrontEnd) but evrey time i get this error ERROR TypeError: this.booksRecieved is not iterable, can any one plaise help me.

This is the function where i get the error.

books: Array<Book>;
  booksRecieved: Array<Book>;

refreshData(){
      this.books=new Array<Book>();
      this.httpClientService.getBooks().subscribe(
        (response) =>      
        //get books returned by the api call
        this.booksRecieved = response,
            
      );
      for (const book of this.booksRecieved) {
        const bookwithRetrievedImageField = new Book();
        bookwithRetrievedImageField.id = book.id;
        bookwithRetrievedImageField.name = book.name;
        //populate retrieved image field so that book image can be displayed
        bookwithRetrievedImageField.retrievedImage = 'data:image/jpeg;base64,' + book.picByte;
        bookwithRetrievedImageField.author = book.author;
        bookwithRetrievedImageField.price = book.price;
        bookwithRetrievedImageField.picByte=book.picByte;
        this.books.push(bookwithRetrievedImageField);
}
Felix
  • 9,248
  • 10
  • 57
  • 89
wahib
  • 373
  • 1
  • 2
  • 12
  • It most likely means that the ‘booksReceived’ is not an array. You should start your debugging process there and see what type of object that variable holds – gion_13 Nov 01 '20 at 20:47
  • Please add the implementation of `getBooks()`. I think you need to get through some Spring tutorial first – Felix Nov 01 '20 at 20:49
  • @Felix evrey think in spring boot is work fine, the problem is in the angular part. – wahib Nov 01 '20 at 20:51
  • @mbojko I already see it, But no, it doesn't solve the problem :( – wahib Nov 01 '20 at 20:53
  • @wahib Have you read the solution? The source of your problem is: you're trying to read the value of `booksRecieved` _before_ receiving the HTTP response. In the linked thread you'll find more or less all possible solutions in JavaScript, including Angular ones. – mbojko Nov 01 '20 at 20:55

0 Answers0