Skip to content

Commit

Permalink
fix value update in readonly form field wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Wagei committed Oct 17, 2024
1 parent 989e4c4 commit c6f9c88
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {ControlContainer, FormGroupDirective} from '@angular/forms';
import {ReadOnlyFormFieldComponent} from '../readonly-form-field/readonly-form-field.component';
import {NgIf} from '@angular/common';
import {ObserversModule} from '@angular/cdk/observers';
import {Subscription} from "rxjs";
import {Subscription} from 'rxjs';

/**
* Wraps a mat-form-field to replace it by a readOnly representation if necessary
Expand Down Expand Up @@ -118,7 +118,7 @@ export class ReadOnlyFormFieldWrapperComponent implements OnInit, AfterViewInit,
}

ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
}

ngOnChanges(_: SimpleChanges): void {
Expand Down Expand Up @@ -183,8 +183,11 @@ export class ReadOnlyFormFieldWrapperComponent implements OnInit, AfterViewInit,
}
if (form && form.get(formControlName)) {
this.value = form.get(formControlName).getRawValue();
this.subscriptions.push(form.get(formControlName).valueChanges
.subscribe(changedValue => this.value = changedValue));
this.subscriptions.push(
form.get(formControlName).valueChanges.subscribe((changedValue) => {
this.value = changedValue;
}),
);
}
}

Expand Down

0 comments on commit c6f9c88

Please sign in to comment.