Skip to content
Snippets Groups Projects
Commit 0d47e235 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

reset state on value change

parent c84d1a6d
No related branches found
No related tags found
1 merge request!529NCM: Data
import {Component, computed, Signal} from '@angular/core';
import {Component, computed, OnDestroy, OnInit, Signal} from '@angular/core';
import {ReactiveFormsModule} from '@angular/forms';
import {MatButtonModule} from '@angular/material/button';
import {MatFormFieldModule} from '@angular/material/form-field';
......@@ -19,6 +19,7 @@ import {Location} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/geo';
import {NshmId} from '@ghsc/nshmp-utils-ts/libs/nshmp-lib/nshm';
import {DoubleParameter} from '@ghsc/nshmp-utils-ts/libs/nshmp-ws-utils/metadata';
import {environment} from 'projects/nshmp-apps/src/environments/environment';
import {Subscription} from 'rxjs';
import {AppService} from '../../services/app.service';
......@@ -39,7 +40,7 @@ import {AppService} from '../../services/app.service';
styleUrl: './control-panel.component.scss',
templateUrl: './control-panel.component.html',
})
export class ControlPanelComponent {
export class ControlPanelComponent implements OnInit, OnDestroy {
formGroup = this.service.formGroup;
parameters = computed(() => this.service.usage()?.response.parameters);
......@@ -62,8 +63,31 @@ export class ControlPanelComponent {
};
});
private subs: Subscription[] = [];
constructor(public service: AppService) {}
ngOnInit(): void {
const controls = this.formGroup.controls;
this.subs.push(
controls.depthInc.valueChanges.subscribe(() => this.service.resetState())
);
this.subs.push(
controls.depthMax.valueChanges.subscribe(() => this.service.resetState())
);
this.subs.push(
controls.depthMin.valueChanges.subscribe(() => this.service.resetState())
);
this.subs.push(
controls.locations.valueChanges.subscribe(() => this.service.resetState())
);
}
ngOnDestroy(): void {
this.subs.forEach(sub => sub.unsubscribe());
}
removeLocation(index: number): void {
this.formGroup.controls.locations.removeAt(index);
}
......
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