I am subscribing a response from an Angular service:
books: BookModel[] = [];
constructor(private bookService: BookService) { }
ngOnInit() {
this.books = this.getBooks();
}
getBooks(): BookModel[] {
return this.bookService.getByCategoryId(1).subscribe((payload: Payload<GetBooksResponse>) => {
return payload.result.map((response: GetBooksResponse) => {
return {
id: response.id,
title: response.title
};
});
});
}
When I add return to this.bookService, e.g., return this.bookService I get the error:
Type 'Subscription' is missing the following properties from type 'BookModel[]': length, pop, push, concat, and 26 more.
How can I use return to make this work?
Update: BookModel:
export interface BookModel {
id: number;
title: string;
}