Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays

后端 未结 18 1187
逝去的感伤
逝去的感伤 2020-11-29 05:50

I looked at similar questions, but none of them helped me. I am going to receive an object like the following:

[
  {
    \"id\": 1,
    \"name\": \"Safa\",
          


        
18条回答
  •  清酒与你
    2020-11-29 06:25

    You can declare the books (on line 2) as an array:

    title: any = 'List of books are represted in the bookstore';
    books: any = []; 
    constructor(private service:  AppService){
    }
    
    ngOnInit(){
      this.getBookDetails();
    }
    
    getBookDetails() {
        this.service.getBooks().subscribe(books => {
            this.books = books.json();
            console.log(this.books);
        });
    }
    

提交回复
热议问题