0

This is my service: https://api.myjson.com/bins/quv59

Im trying to display it in my html

*ngFor="let item of booksList; let i = index"

my ts file

ngOnInit() {
  this.booksDataService.getBooks().subscribe(
  function(response) { 
    this.booksList = response.books;
  },
);}

thanks in advance

eladr
  • 343
  • 1
  • 4
  • 18
  • Possible duplicate of [How to access the correct \`this\` inside a callback?](https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback) – AT82 Jul 28 '17 at 11:31

3 Answers3

1
  <li *ngFor="let item of booksList; let i = index">
    {{ item.author }} 
  </li>
wesside
  • 5,622
  • 5
  • 30
  • 35
  • I even didnt try to print the value - i have some hard coded just cant see anything... This is my service but when i print booklist to the log i can see array of 7 objects so i beleive it's ok – eladr Jul 27 '17 at 21:10
  • @eladr item of bookList.Books – wesside Jul 28 '17 at 18:50
0

This is the correct answer for the help of other people... call to the service:

this.booksDataService.getBooks()
    .subscribe(
        allBooks => this.booksList = allBooks);}

html:

*ngFor="let item of booksList.books; let i = index"
eladr
  • 343
  • 1
  • 4
  • 18
0

Here is the solution using async pipe:

*ngFor="let item of booksDataService.getBooks() | async; let i = index"
Sonu Kapoor
  • 1,567
  • 3
  • 16
  • 34