angular - 错误类型错误:无法读取 SafeSubscriber.settingsService.create.subscribe.loading [as _next] 处未定义的属性“重置”
问题描述
我正在做一个 Angular 11 项目。
提交表单时出现此错误。
ERROR TypeError: Cannot read property 'reset' of undefined at SafeSubscriber.settingsService.create.subscribe.loading [as _next]
我的组件.ts
import { NbStepperComponent} from '@nebular/theme';
@ViewChild('settingFormStepper') settingFormStepper: NbStepperComponent;
this.settingsService.create(formData)
.subscribe((settings) => {
this.toastrService.show(' Settings added', { status: 'success', duration: 10000 });
this.settingsService.resetForm();
this.settingFormStepper.reset(); // error on this this line
}
.html 文件
<nb-card-body *ngIf="!loading" >
<form [formGroup]="sitesettingForm">
<nb-stepper #settingFormStepper [disableStepNavigation]="true" orientation="horizontal">
<nb-step> </nb-step>
</nb-stepper>
</form>
</nb-card-body>
我做错了什么?
解决方案
当您<nb-stepper>
尝试调用reset()
. 所以,this.settingFormStepper
是undefined
。你能提供整个 HTML 模板吗?或者,你有任何包装它吗*ngIf
?<nb-stepper>