[英]Function update contact is not defined, although it is defined
I have here angular code:我这里有 angular 代码:
@Component({
selector: 'app-detail-view',
templateUrl: './detail-view.component.html',
styleUrls: ['./detail-view.component.css']
})
export class DetailViewComponent implements OnInit {
detailLable:string;
contactId: number;
contact:Contact = null;
constructor(
private contactService: ContactService,
private route: ActivatedRoute,
private location: Location
) {}
ngOnInit(): void {
this.contactId = +this.route.snapshot.paramMap.get('id');
if(this.contactId == 0){
this.contact = {id : null, firstName : null, surname : null, email: null, phone: null};
this.detailLable = 'New contact'
} else {
this.contactService.getContact(this.contactId).subscribe(contact => this.contact = contact);
this.detailLable = 'Edit contact with id :' + this.contactId;
}
}
updateContact( contact: Contact): void{
this.contact = contact;
this.detailLable = "Edit contact with id " +contact.id
}
goBack(): void {
this.location.back();
}
save():void {
// this.contact = this.contactService.saveContact(this.contact).subscribe(contact => this.contact = contact, complete: () => console.log(this.detailLable = this.contact.id));
this.contactService.saveContact(this.contact).subscribe(contact => updateContact(contact));
}
new() : void {
this.contact = {id : null, firstName : null, surname : null, email: null, phone: null};
}
}
when I call save, It return me that updateContact method is not defined.当我调用保存时,它返回我未定义 updateContact 方法。 Can someone give me a point, how to solve this issue?有人可以给我一点,如何解决这个问题? It seems, that is something wrong with method declaration.看来,方法声明有问题。
updateContact
is defined on the class, so this.updateContact
should work. updateContact
是在 class 上定义的,所以this.updateContact
应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.