@ngx-formly/core 6.0.2 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/components/formly.field.mjs +18 -1
- package/esm2020/lib/extensions/field-expression/field-expression.mjs +8 -19
- package/esm2020/lib/models/fieldconfig.cache.mjs +1 -1
- package/esm2020/lib/templates/field-array.type.mjs +3 -2
- package/fesm2015/ngx-formly-core.mjs +30 -21
- package/fesm2015/ngx-formly-core.mjs.map +1 -1
- package/fesm2020/ngx-formly-core.mjs +26 -19
- package/fesm2020/ngx-formly-core.mjs.map +1 -1
- package/lib/models/fieldconfig.cache.d.ts +4 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Type, TemplateRef, ComponentRef, ChangeDetectorRef, InjectionToken, Injectable, Optional, Directive, Input, ViewContainerRef, Component, ViewChild, EventEmitter, ChangeDetectionStrategy, Output, ContentChildren, Inject, NgModule } from '@angular/core';
|
|
3
3
|
import * as i2 from '@angular/forms';
|
|
4
4
|
import { AbstractControl, FormGroup, FormArray, FormControl, Validators } from '@angular/forms';
|
|
5
|
-
import { isObservable, merge, of, Observable, Subject } from 'rxjs';
|
|
5
|
+
import { isObservable, merge, of, Observable, tap, Subject } from 'rxjs';
|
|
6
6
|
import { distinctUntilChanged, startWith, debounceTime, filter, switchMap, take, map } from 'rxjs/operators';
|
|
7
7
|
import * as i2$1 from '@angular/common';
|
|
8
8
|
import { DOCUMENT, CommonModule } from '@angular/common';
|
|
@@ -889,6 +889,23 @@ class FormlyField {
|
|
|
889
889
|
observeDeep(field, ['props'], () => field.options.detectChanges(field)),
|
|
890
890
|
observeDeep(field.options, ['formState'], () => field.options.detectChanges(field)),
|
|
891
891
|
];
|
|
892
|
+
for (const key of Object.keys(field._expressions)) {
|
|
893
|
+
const expressionObserver = observe(field, ['_expressions', key], ({ currentValue, previousValue }) => {
|
|
894
|
+
if (previousValue?.subscription) {
|
|
895
|
+
previousValue.subscription.unsubscribe();
|
|
896
|
+
previousValue.subscription = null;
|
|
897
|
+
}
|
|
898
|
+
if (isObservable(currentValue.value$)) {
|
|
899
|
+
currentValue.subscription = currentValue.value$.subscribe();
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
subscribes.push(() => {
|
|
903
|
+
if (field._expressions[key]?.subscription) {
|
|
904
|
+
field._expressions[key].subscription.unsubscribe();
|
|
905
|
+
}
|
|
906
|
+
expressionObserver.unsubscribe();
|
|
907
|
+
});
|
|
908
|
+
}
|
|
892
909
|
for (const path of [['template'], ['fieldGroupClassName'], ['validation', 'show']]) {
|
|
893
910
|
const fieldObserver = observe(field, path, ({ firstChange }) => !firstChange && field.options.detectChanges(field));
|
|
894
911
|
subscribes.push(() => fieldObserver.unsubscribe());
|
|
@@ -1408,7 +1425,8 @@ class FieldArrayType extends FieldType {
|
|
|
1408
1425
|
markAsDirty && this.formControl.markAsDirty();
|
|
1409
1426
|
}
|
|
1410
1427
|
_build() {
|
|
1411
|
-
this.
|
|
1428
|
+
const fields = this.field.formControl._fields ?? [this.field];
|
|
1429
|
+
fields.forEach((f) => this.options.build(f));
|
|
1412
1430
|
this.options.fieldChanges.next({
|
|
1413
1431
|
field: this.field,
|
|
1414
1432
|
value: getFieldValue(this.field),
|
|
@@ -1510,22 +1528,11 @@ class FieldExpressionExtension {
|
|
|
1510
1528
|
field._expressions[key] = this.parseExpressions(field, key, expr);
|
|
1511
1529
|
}
|
|
1512
1530
|
else if (expr instanceof Observable) {
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
field.hooks.onInit = () => {
|
|
1519
|
-
if (subscription === null) {
|
|
1520
|
-
subscription = subscribe();
|
|
1521
|
-
}
|
|
1522
|
-
return onInit?.(field);
|
|
1523
|
-
};
|
|
1524
|
-
const onDestroy = field.hooks.onDestroy;
|
|
1525
|
-
field.hooks.onDestroy = () => {
|
|
1526
|
-
onDestroy?.(field);
|
|
1527
|
-
subscription.unsubscribe();
|
|
1528
|
-
subscription = null;
|
|
1531
|
+
field._expressions[key] = {
|
|
1532
|
+
value$: expr.pipe(tap((v) => {
|
|
1533
|
+
this.evalExpr(field, key, v);
|
|
1534
|
+
field.options.detectChanges(field);
|
|
1535
|
+
})),
|
|
1529
1536
|
};
|
|
1530
1537
|
}
|
|
1531
1538
|
};
|
|
@@ -1619,7 +1626,7 @@ class FieldExpressionExtension {
|
|
|
1619
1626
|
let fieldChanged = false;
|
|
1620
1627
|
if (field._expressions) {
|
|
1621
1628
|
for (const key of Object.keys(field._expressions)) {
|
|
1622
|
-
field._expressions[key].callback(ignoreCache) && (fieldChanged = true);
|
|
1629
|
+
field._expressions[key].callback?.(ignoreCache) && (fieldChanged = true);
|
|
1623
1630
|
}
|
|
1624
1631
|
}
|
|
1625
1632
|
field.fieldGroup?.forEach((f) => this.checkExpressions(f, ignoreCache) && (fieldChanged = true));
|