使用异步管道和主题时的ObjectUnsunscriberError实现

时间:2019-09-07 15:28:19

标签: angular rxjs angular6 observable subject

我正在使用异步管道来显示基于用户选项的几种表单,我正在使用主题和异步管道来动态生成表单。它正在运行,但是出现以下控制台错误:

模板:     

     <div *ngIf="observable">
        <form-builder [config]="observable"
          [config$]="subject$" [formGroup]="formGroup">
        </form-builder>
      </div>
</div>

组件

this.observable$ = this.formControl.valueChanges.pipe(
      map((control: string) => {
        if (!control) {
          this.subject$.unsubscribe();
          return null;   //// When I dont return null its not giving error
        }

        if (this.subject$.closed) {
          this.subject$ = new Subject<
            FormBuilderConfig
          >();
        }

        this.subject$.next(newFormBuilderConfig);
        return newFormBuilderConfig;
      })
    );

控制台错误:

Error Occurred while building and resolving component from factory.  TypeError: Cannot read property 'valueChanges' of undefined
    at FormBuilderComponent.push


 ObjectUnsubscribedErrorImpl {message: "object unsubscribed", name: "ObjectUnsubscribedError", ngDebugContext: DebugContext_, ngErrorLogger: ƒ}
    message: "object unsubscribed"
    name: "ObjectUnsubscribedError"
    ngDebugContext: DebugContext_ {view: {…}, nodeIndex: 2, nodeDef: {…}, elDef: {…}, elView: {…}}
    ngErrorLogger: ƒ ()
    __proto__: Error

0 个答案:

没有答案