From a1266746986afdbf0d5052573805e2bf499c4bf5 Mon Sep 17 00:00:00 2001
From: jojohoch <joachim.hoch@iqb.hu-berlin.de>
Date: Mon, 28 Nov 2022 10:47:39 +0100
Subject: [PATCH] [editor] Fix initialization of GeoGebra elements when loading
 a 2nd unit

---
 .../canvas/overlays/canvas-element-overlay.ts         | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/projects/editor/src/app/components/canvas/overlays/canvas-element-overlay.ts b/projects/editor/src/app/components/canvas/overlays/canvas-element-overlay.ts
index 43d861a9b..d4105f7cb 100644
--- a/projects/editor/src/app/components/canvas/overlays/canvas-element-overlay.ts
+++ b/projects/editor/src/app/components/canvas/overlays/canvas-element-overlay.ts
@@ -12,11 +12,10 @@ import { CompoundChildOverlayComponent } from
 import { DragNDropValueObject, UIElement } from 'common/models/elements/element';
 import { GeometryComponent } from 'common/components/geometry/geometry.component';
 import { GeometryElement } from 'common/models/elements/geometry/geometry';
-import { UnitService } from '../../../services/unit.service';
-import { SelectionService } from '../../../services/selection.service';
 import { DropListComponent } from 'common/components/input-elements/drop-list.component';
-import { DropListElement } from 'common/models/elements/input-elements/drop-list';
 import { FormElementComponent } from 'common/directives/form-element-component.directive';
+import { UnitService } from '../../../services/unit.service';
+import { SelectionService } from '../../../services/selection.service';
 
 @Directive()
 export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
@@ -36,6 +35,9 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
   ngOnInit(): void {
     this.childComponent = this.elementContainer.createComponent(this.element.getElementComponent());
     this.childComponent.instance.elementModel = this.element;
+    if (this.childComponent.instance instanceof GeometryComponent) {
+      this.childComponent.instance.appDefinition = (this.element as GeometryElement).appDefinition;
+    }
     this.childComponent.changeDetectorRef.detectChanges(); // this fires onInit, which initializes the FormControl
     if (this.childComponent.instance instanceof FormElementComponent) {
       (this.childComponent.instance as FormElementComponent).elementFormControl.setValue(this.element.value);
@@ -48,9 +50,6 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
     // Make children not clickable. This way the only relevant events are managed by the overlay.
     this.childComponent.location.nativeElement.style.pointerEvents = 'none';
 
-    if (this.childComponent.instance instanceof GeometryComponent) {
-      this.childComponent.instance.appDefinition = (this.element as GeometryElement).appDefinition;
-    }
     if (this.childComponent.instance instanceof ClozeComponent) {
       // make cloze element children clickable to access child elements
       this.childComponent.instance.editorMode = true;
-- 
GitLab