1

I want to open the components as a dialog via the use case service. The dialog itself contains the use case service to call functions. Unfortunately an Uncaught ReferenceError: Cannot access 'f' before initialization occurs in the following implementation. Why does the error occur and how can I solve it?

The problem occurs because the dialog is opened in the use case or the dialog then contains the use case. If I call another component, the error does not occur. The error also does not occur if I remove the use case service from the component.

@Injectable()
export class ManageRuleBuilderDialogUsecase {
  constructor(
    private store: Store,
    private dialog: MatDialog,
  ) {}

  public openEmptyRuleBuilderDialog(): void {
    this.dialog.open(RuleBuilderDialogComponent, {
      width: modalWidth,
      height: modalHeight,
    });
  }

  public addAction(): void {
    ...
  }
}
@Component({...})
export class RuleBuilderDialogComponent implements OnInit {
 constructor(
    private store: Store,
    private dialog: MatDialogRef<RuleBuilderDialogComponent>,
    private manageRuleBuilderDialogUsecase: ManageRuleBuilderDialogUsecase
  ) {}

  public onAddAction(): void {
    this.manageRuleBuilderDialogUsecase.addAction();
  }
  ...
}
laprof
  • 1,246
  • 3
  • 14
  • 27
  • Can you show what stuff you're doing "onInit" function ? Your error probably comes from there. – millenion Oct 01 '21 at 10:23
  • I have edited my question with additional information. I have completely commented out onInit and the error still occurs. – laprof Oct 01 '21 at 10:25
  • Maybe this helps you https://stackoverflow.com/questions/56870661/angular-7-2-1-es6-class-referenceerror-cannot-access-x-before-initializatio – Gunnar B. Oct 01 '21 at 10:57

0 Answers0