Angular获取意外/无法解释的空引用

时间:2019-05-10 03:57:34

标签: angular

我收到了“无法读取null的属性'markAsPristine'”错误,这是完全意外的,没有任何意义。这在99%的时间内都有效,但是在极少数情况下,我在markAsPristine上收到空引用错误。我不知道在那条线上它怎么可能为空。有什么想法吗?

我用以下错误标记了这一行。但是,如果您遵循该代码,则该行为空应该是不可能的。只需遵循下面的代码即可。

这是我的代码。

var parent = this;
this._contactService.saveContact(this.subscriberCode, this.contactId, {
  firstName: this.pageForm.controls.firstName.value,  /* This line works, so pageForm is not null here */
  lastName: this.pageForm.controls.lastName.value,
  address1: this.pageForm.controls.address1.value,
  address2: this.pageForm.controls.address2.value,
  city: this.pageForm.controls.city.value,
  state: this.pageForm.controls.state.value,
  zipCode: this.pageForm.controls.zipCode.value
})
  .subscribe(response => {
    parent.pageForm.markAsPristine();  /* this is where we get the error */
    this.messageAlert = 'Changes have been saved';
  }, (respError: HttpErrorResponse) => {
    this.messageAlert = this._errorReportService.formatResponseError(respError, `savePage()`);
  });

0 个答案:

没有答案
相关问题