我在打字稿中有一个弱依赖错误。
类型标题没有与类型相同的属性。
我正在尝试使用2种不同的方法将帖子和删除请求发送到另一个api。 我的ts代码在使用中有2种不同的方法,第一个“ addcustomer”可以正常工作,而第二个“ deletecustomer”则不能,
addcustomer(customer: string, disable: boolean): Observable<customer> {
const newAddcustomerModel = {
customer: customer, disable: disable
} as AddcustomerModel;
return this.http.post<customer>(`/api/admin/add-customers`, newAddcustomerModel);
}
deletecustomer(id: number): Observable<customer> {
const newcustomerModel = {
id: id
} as DeletecustomerModel;
return this.http.delete<customer>(`/api/admin/delete-customers`, newcustomerModel)
}
及其模型
export interface AddCustomerModel {
customer: string;
disable: boolean;
}
第二个是:
export interface DeleteCustomerModel {
id: number;
}
错误出现在 newcustomerModel 上,该错误位于最后一行的 deletecustomer()方法中。
答案 0 :(得分:2)
创建HttpHeaders
实例以分配标头
let newcustomerModel = new HttpHeaders({
id: id
} )
this.http.delete<customer>(`/api/admin/delete-customers`, {headers: newcustomerModel })