我正在尝试从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);
}
}