concept book component in category aurelia

appears as: books component, book component, The book component, books components
Aurelia in Action

This is an excerpt from Manning's book Aurelia in Action.

Listing 3.8. View-model for the books component (books.js)
import {bindable, inject} from 'aurelia-framework';
import {BookApi} from '../../services/book-api';

@inject(BookApi)
export class Books{                   #1
  ..
   addBook () {
       this.books.push({title : this.bookTitle});
       this.bookTitle = "";
   }
  ..
}

In chapter 2, you set up a parent-child relationship between the books component and the book-list component, as shown in figure 6.4.

Figure 6.7. Following the data-down, actions-up approach, use one-way data binding to pass the books array to the book-list (as you’re doing already), and then use the Event Aggregator to publish the book-removed event back up to the book component so that it can update the array.

Next, you’ll move the implementation of the removeBook method from the book-list component to the book component. This method raises an event on the Event Aggregator that a specific book has been removed. Following this, you’ll create a method to toggle the edit mode to be called when the Edit button from the view is clicked. Finally, you’ll set up the relevant event subscription and event-cleanup behavior in the subscribeToEvents and unbind methods.