Why is the 'book.isEqual' method of the Book class not recognized as a function when called in the BooksService class?
In file: models/book.model.ts
export class Book {
constructor(public title: string, public author: string) {
}
isEqual (other: Book ): boolean {
return (this === other);
}
}
In file: services/books.service.ts
import { Book } from '../models/book.model';
import { Subject } from 'rxjs/Subject';
import * as firebase from 'firebase';
import DataSnapshot = firebase.database.DataSnapshot;
export class BooksService {
books = [new Book ('', '')]
booksSubject = new Subject<Book[]>();
constructor() {
this.getBooks();
}
emitBooks() {
this.booksSubject.next(this.books);
}
getBooks() {
firebase.database().ref('/books')
.on('value',
(data: DataSnapshot) =>
{
this.books = data.val() ? data.val() : [];
this.emitBooks(); /
}
);
}
indexOfBook (book: Book) {
const bookIndex = this.books.findIndex(
(a_book) => {return book.isEqual (a_book)}
);
return bookIndex;
}
I am trying to use the 'book.isEqual' method from the Book class within the BooksService class, but it is not working. What could be the reason for this issue?