我正在使用Angular框架,我仍在尝试解决问题...我正在使用Restangular发布
供参考:
feedback: Feedback; (feedback class)
feedbackCopy = null; (to be used to check for form entry before posting to server)
feedbackForm = FormGroup;
我正在整理一个表单,该表单将获取输入信息,并将其发布到服务器。
onSubmit(){
//store form values in feedback object
this.feedback = this.feedbackForm.value;
//log object to console
console.log(this.feedback);
//give feedback info to feedback class to be stored in object
this.feedbackCopy.push(this.feedback);
this.feedbackCopy.save().subscribe(feedback => { this.feedback = feedback; console.log(this.feedback)})
//reset for to empty values
this.feedbackForm.reset({
firstname: '',
lastname: '',
telnum: '',
email: '',
agree: false,
contacttype: 'None',
message: ''
});
}
以上是应该将信息发布到服务器的Submit函数的代码。它停在
this.feedbackCopy.push(this.feedback);
行并说.push不是函数
ERROR TypeError: this.feedbackCopy.push is not a function
at ContactComponent.onSubmit (contact.component.ts:122)
我错过了一些明显的东西吗?
答案 0 :(得分:0)
在调用onSubmit()
之前,您需要准备feedbackCopy作为正确的类型(即,restangular)