web-dave / angular-starter-v2

6 stars 3 forks source link

use BooksService #9

Open web-dave opened 7 years ago

web-dave commented 7 years ago
web-dave commented 7 years ago

generate (if not exists!!)

  ng g c books/book-list
web-dave commented 7 years ago

book-list.component.ts

  constructor(private booksService: BooksService) { }
  ngOnInit() {
    this.booksService.getBooks().subscribe(books => this.books = books);
  }
web-dave commented 7 years ago

book-list.component.html

  <ul *ngIf="books">
   <li *ngFor="let book of books">{{book.title}}</li>
  </ul>