I encountered an issue while trying to add a new book to my books array and received an error message. https://i.sstatic.net/PaUA8.png
This pertains to the book-edit.component.ts
When initializing:
Upon initializing, I subscribed to changes in authors through the authors service. This is triggered when there are changes made to the authors list.
this.authors = authors;
I also called for the retrieval of authors using the getAuthors() method provided by the authors service.
The bookForm instance was created with pre-filled values for various form controls such as id, title, author, description, publishYear, and image.
In the onSubmit() method: Upon form submission, the values entered in the form are captured and assigned to respective properties of a book object. const book = { id: this.bookForm.value.id, title: this.bookForm.value.title, author: this.bookForm.value.author, description: this.bookForm.value.description, publishYear: this.bookForm.value.publishYear, image: this.bookForm.value.image }; The addBook() method from the booksService is then called with the newly created book object passed as an argument.
Function from the booksService.ts:
The addBook(book: Book) method within the books service is responsible for adding a new book into the beginning of the books array. It notifies subscribers about the change in the books array by emitting the updated array via the booksChanged subject.