Angular 错误TS2322:类型';对象';不可分配给类型';联系';。有棱角的
我想运行我的项目以在前端保存联系人我在IDE webStorm中读到这个错误src/app/new contact/new contact.component.ts(24,9):错误TS2322:类型“Object”不能分配给类型“contact”。 “对象”类型可分配给很少的其他类型。你的意思是用“any”类型吗? 类型“Object”中缺少属性“id”。 在newcontact.component.ts(24,9)(at.subscribe((data))行中,我有这个代码Angular 错误TS2322:类型';对象';不可分配给类型';联系';。有棱角的,angular,angular5,angular6,angular-services,Angular,Angular5,Angular6,Angular Services,我想运行我的项目以在前端保存联系人我在IDE webStorm中读到这个错误src/app/new contact/new contact.component.ts(24,9):错误TS2322:类型“Object”不能分配给类型“contact”。 “对象”类型可分配给很少的其他类型。你的意思是用“any”类型吗? 类型“Object”中缺少属性“id”。 在newcontact.component.ts(24,9)(at.subscribe((data))行中,我有这个代码 saveCont
saveContact(){
this.contactService.saveContact(this.contact)
.subscribe((data) => {
this.contact = data;
this.mode = 2;
}, err=>{
console.log("ErReUr : "+err);
});
}
我有服务代码
saveContact(contact: Contact){
return this.http.post("http://localhost:8080/addPerson", contact);
}
我在项目中有一个我的类,但在项目中的一个文件中,这是代码
export class Contact {
any = null;
nom: string = '';
prenom: string = '';
email: string = '';
tel: number = 0;
photo: string = '';
dateNAissance:Date;
}
问题出在触点的id和对象中
请帮助我,我需要一个解决方案,谢谢:)请尝试编写您的服务:
saveContact(contact: Contact){
return this.http.post("http://localhost:8080/addPerson", contact) as Observable<Contact>;
}
saveContact(联系人:contact){
返回此.http.post(“http://localhost:8080/addPerson“,接触)视为可见;
}
也就是说,将其作为可观察的触点类型返回