diff --git a/ui/src/app/schema-form/widget/check/checklist.component.ts b/ui/src/app/schema-form/widget/check/checklist.component.ts index 16dd3224a..e7a056690 100644 --- a/ui/src/app/schema-form/widget/check/checklist.component.ts +++ b/ui/src/app/schema-form/widget/check/checklist.component.ts @@ -1,16 +1,18 @@ -import { Component, AfterViewInit } from '@angular/core'; +import { Component, AfterViewInit, OnDestroy } from '@angular/core'; import { ArrayWidget } from 'ngx-schema-form'; import { AttributesService } from '../../../metadata/domain/service/attributes.service'; -import { Observable, of } from 'rxjs'; +import { Observable, of, Subscription } from 'rxjs'; /* istanbul ignore next */ @Component({ selector: 'checklist-component', templateUrl: `./checklist.component.html` }) -export class ChecklistComponent extends ArrayWidget implements AfterViewInit { +export class ChecklistComponent extends ArrayWidget implements AfterViewInit, OnDestroy { checked: any = {}; + currentData: { key: string, label: string }[]; + sub: Subscription; constructor( private attributes: AttributesService @@ -21,6 +23,12 @@ export class ChecklistComponent extends ArrayWidget implements AfterViewInit { ngAfterViewInit(): void { super.ngAfterViewInit(); this.formProperty.value.forEach(val => this.checked[val] = true); + + this.sub = this.data.subscribe(d => this.currentData = d); + } + + ngOnDestroy(): void { + this.sub.unsubscribe(); } private commitValue(): void { @@ -41,11 +49,11 @@ export class ChecklistComponent extends ArrayWidget implements AfterViewInit { } onCheckAll(): void { - this.schema.widget.data.forEach(attr => this.checked[attr.key] = true); + this.currentData.forEach(attr => this.checked[attr.key] = true); this.commitValue(); } onCheckNone(event: Event | null = null): void { - this.schema.widget.data.forEach(attr => { + this.currentData.forEach(attr => { delete this.checked[attr.key]; }); this.commitValue();