Skip to content
Snippets Groups Projects
Commit 2daf595f authored by jojohoch's avatar jojohoch
Browse files

[player] Fix restoring of toggle buttons

- Explicitly set the value of the form control of CompoundChildren,
because they are not yet fully registered in the onInit phase.
- Use ChangeDetectorRef to prevent
ExpressionChangedAfterItHasBeenCheckedError
parent f86f5511
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import { FormElementComponent } from '../../directives/form-element-component.di
template: `
<div class="mat-form-field">
<mat-button-toggle-group [formControl]="elementFormControl"
[value]="elementModel.value"
[style.height.px]="elementModel.height">
<mat-button-toggle *ngFor="let option of elementModel.options; let i = index"
[value]="i"
......
import {
Component, OnInit, Input, ComponentFactoryResolver, ViewChild, ViewContainerRef, QueryList
Component, OnInit, Input, ComponentFactoryResolver, ViewChild, ViewContainerRef, QueryList, ChangeDetectorRef
} from '@angular/core';
import {
FormBuilder, FormControl, FormGroup, ValidatorFn
......@@ -59,7 +59,8 @@ export class ElementContainerComponent implements OnInit {
private veronaPostService: VeronaPostService,
private mediaPlayerService: MediaPlayerService,
private unitStateElementMapperService: UnitStateElementMapperService,
private markingService: MarkingService) {
private markingService: MarkingService,
private changeDetectorRef: ChangeDetectorRef) {
}
ngOnInit(): void {
......@@ -119,8 +120,8 @@ export class ElementContainerComponent implements OnInit {
elementComponent.parentForm = elementForm;
const compoundChildren = elementComponent.getFormElementModelChildren();
this.subscribeCompoundChildren(elementComponent, compoundChildren);
this.registerFormGroup(elementForm);
compoundChildren.forEach((element: InputElement) => {
this.registerFormGroup(elementForm);
this.formService.registerFormControl({
id: element.id,
formControl: new FormControl(element.value),
......@@ -165,7 +166,12 @@ export class ElementContainerComponent implements OnInit {
child.domElement,
this.pageIndex
);
const formChild = (child as FormElementComponent);
if (formChild) {
formChild.setFormValue(child.elementModel.value);
}
});
this.changeDetectorRef.detectChanges();
});
}
}
......
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