Skip to content
Snippets Groups Projects
Commit a1f7b66c authored by rhenck's avatar rhenck
Browse files

[editor] Fix small bug with element selection

Adding elements to other section caused the old "NG0100: Expression has 
changed after it was checked".
We now manually do change detection when we update the selection 
variable.
parent 1d0274aa
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ import { ...@@ -2,7 +2,7 @@ import {
Directive, Input, Directive, Input,
ComponentFactoryResolver, ComponentRef, ComponentFactoryResolver, ComponentRef,
HostListener, HostListener,
ViewChild, ViewContainerRef, OnInit, OnDestroy ViewChild, ViewContainerRef, OnInit, OnDestroy, ChangeDetectorRef
} from '@angular/core'; } from '@angular/core';
import { forkJoin, Subject } from 'rxjs'; import { forkJoin, Subject } from 'rxjs';
import { take, takeUntil } from 'rxjs/operators'; import { take, takeUntil } from 'rxjs/operators';
...@@ -25,11 +25,8 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { ...@@ -25,11 +25,8 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
constructor(public selectionService: SelectionService, constructor(public selectionService: SelectionService,
protected unitService: UnitService, protected unitService: UnitService,
private componentFactoryResolver: ComponentFactoryResolver) { private componentFactoryResolver: ComponentFactoryResolver,
// Needs to be run before change detection to set 'selected' and avoid private changeDetectorRef: ChangeDetectorRef) { }
// NG0100: Expression has changed after it was checked
this.selectionService.selectElement({ componentElement: this, multiSelect: false });
}
ngOnInit(): void { ngOnInit(): void {
const componentFactory = ComponentUtils.getComponentFactory(this.element.type, this.componentFactoryResolver); const componentFactory = ComponentUtils.getComponentFactory(this.element.type, this.componentFactoryResolver);
...@@ -74,6 +71,10 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { ...@@ -74,6 +71,10 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
setSelected(newValue: boolean): void { setSelected(newValue: boolean): void {
this.selected = newValue; this.selected = newValue;
// This avoids: "NG0100: Expression has changed after it was checked"
// The selection service may change the "selected" variable after onInit has run.
// Therefore we need to run it again after this.
this.changeDetectorRef.detectChanges();
} }
selectElement(multiSelect: boolean = false): void { selectElement(multiSelect: boolean = false): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment