@@ -6,6 +6,7 @@ import {MatDivider} from '@angular/material/list';
66import { MatFormField , MatLabel , MatInput } from '@angular/material/input' ;
77import { MatIconButton , MatButton } from '@angular/material/button' ;
88import { MatIcon } from '@angular/material/icon' ;
9+ import { Subscription } from 'rxjs' ;
910
1011interface RasterbandsForm {
1112 rasterbands : FormArray < FormGroup < RasterbandForm > > ;
@@ -29,7 +30,10 @@ export class RasterbandsComponent implements OnChanges {
2930
3031 form : FormGroup < RasterbandsForm > = this . setUpForm ( ) ;
3132
33+ sub ?: Subscription ;
34+
3235 ngOnChanges ( changes : SimpleChanges ) : void {
36+ console . log ( 'RasterbandsComponent.ngOnChanges' , changes ) ;
3337 if ( changes . rasterbands ) {
3438 this . form = this . setUpForm ( ) ;
3539 }
@@ -64,7 +68,11 @@ export class RasterbandsComponent implements OnChanges {
6468 rasterbands : new FormArray < FormGroup < RasterbandForm > > ( rasterbands ?. map ( ( p ) => this . createRasterbandForm ( p ) ) ?? [ ] ) ,
6569 } ) ;
6670
67- form . valueChanges . subscribe ( ( ) => {
71+ if ( this . sub ) {
72+ this . sub . unsubscribe ( ) ;
73+ }
74+
75+ this . sub = form . valueChanges . subscribe ( ( ) => {
6876 this . rasterbandsChange . emit ( this . getRasterbands ( ) ) ;
6977 } ) ;
7078
@@ -76,6 +84,7 @@ export class RasterbandsComponent implements OnChanges {
7684 name : new FormControl ( p ?. name ?? '' , {
7785 nonNullable : true ,
7886 validators : [ Validators . required , geoengineValidators . notOnlyWhitespace ] ,
87+ updateOn : 'blur' ,
7988 } ) ,
8089 measurement : new FormControl ( p ?. measurement ?? { type : 'unitless' } , {
8190 nonNullable : true ,
0 commit comments