angular - Angular 8:试图捕捉构造函数,但不返回值
问题描述
我正在尝试从 Angular 8 服务调用构造函数;
我之前做过这个 CRUD 操作,但是这次不能正常工作,我找不到原因。
我在这个时候尝试了很多事情,我很头疼,我不知道该怎么办。
请我感谢谁帮助我解决这个问题。
构造函数对象
export class Book {
constructor(
_id = "",
title = "",
author = "",
genre = "",
details: any,
status: any,
current: any
) {
this._id = _id;
this.title = title;
this.author = author;
this.genre = genre;
this.details = details;
this.status = status;
this.current = current;
}
_id: string;
title: string;
author: string;
genre: string;
details: {
publisher: string;
year: string;
isbn: number;
categories: string;
language: string;
pages: number;
};
status: {
loan: boolean;
sold: boolean;
lost: boolean;
donated: boolean;
};
current: {
owner: string;
location: string;
edition: string;
};
角服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Book } from './bookmodel';
@Injectable({
providedIn: 'root'
})
export class BookserviceService {
selectedBook: Book;
Book: Book[];
readonly URL_API = `http://localhost:9000/`;
constructor(private http: HttpClient) {
**ERROR LINE***
this.selectedBook = new Book(); <-- (Expected 7 arguments, but got 0.ts(2554) bookmodel.ts(3, 5): An argument for '_id' was not provided.)
}
postBook(book: Book) {
return this.http.post(this.URL_API, book);
}
getBook() {
return this.http.get(this.URL_API);
}
putBook(book: Book) {
return this.http.put(this.URL_API + `/${book._id}`, book);
}
deleteBook(_id: string) {
return this.http.delete(this.URL_API + `/${_id}`);
}
searchBook(queryString: string) {
const baseURL = this.URL_API + queryString;
return this.http.get(baseURL);
}
}