diff --git a/CHANGELOG.md b/CHANGELOG.md index 99b2dff..3abb480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [5.0.1](https://github.com/ngneat/error-tailor/compare/v5.0.0...v5.0.1) (2023-12-03) + + +### Bug Fixes + +* 🐛 resolve anchor on demand ([646db4f](https://github.com/ngneat/error-tailor/commit/646db4f7e14ae7ea5532025b60729bb4d453eb67)) + ## [5.0.0](https://github.com/ngneat/error-tailor/compare/v4.1.2...v5.0.0) (2023-11-28) diff --git a/projects/ngneat/error-tailor/package.json b/projects/ngneat/error-tailor/package.json index c7bd234..2e533ef 100644 --- a/projects/ngneat/error-tailor/package.json +++ b/projects/ngneat/error-tailor/package.json @@ -1,6 +1,6 @@ { "name": "@ngneat/error-tailor", - "version": "5.0.0", + "version": "5.0.1", "description": "Seamless form errors for Angular Applications", "dependencies": { "tslib": "2.5.0" diff --git a/projects/ngneat/error-tailor/src/lib/control-error.directive.ts b/projects/ngneat/error-tailor/src/lib/control-error.directive.ts index aba348c..4b278db 100644 --- a/projects/ngneat/error-tailor/src/lib/control-error.directive.ts +++ b/projects/ngneat/error-tailor/src/lib/control-error.directive.ts @@ -55,7 +55,6 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { @Input() controlErrorAnchor: ControlErrorAnchorDirective; private ref: ComponentRef; - private anchor: ViewContainerRef; private submit$: Observable; private reset$: Observable; private control: AbstractControl; @@ -72,7 +71,7 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { @Optional() private controlErrorAnchorParent: ControlErrorAnchorDirective, @Optional() private form: FormActionDirective, @Optional() @Self() private ngControl: NgControl, - @Optional() @Self() private controlContainer: ControlContainer + @Optional() @Self() private controlContainer: ControlContainer, ) { this.host = elementRef.nativeElement as HTMLElement; this.submit$ = this.form ? this.form.submit$ : EMPTY; @@ -82,7 +81,6 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { ngOnInit() { this.mergedConfig = this.buildConfig(); - this.anchor = this.resolveAnchor(); this.control = (this.controlContainer || this.ngControl).control; const hasAsyncValidator = !!this.control.asyncValidator; @@ -130,13 +128,13 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { this.submit$.pipe(map(() => true)), this.reset$.pipe( map(() => false), - tap(() => this.hideError()) - ) + tap(() => this.hideError()), + ), ); // when submitted, submitFirstThenUponChanges const changesOnSubmit$ = submit$.pipe( - switchMap((submit) => (submit ? controlChanges$.pipe(startWith(true)) : NEVER)) + switchMap((submit) => (submit ? controlChanges$.pipe(startWith(true)) : NEVER)), ); // on reset, clear ComponentRef and customAnchorDestroyFn @@ -159,7 +157,7 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { return; } - this.ref ??= this.anchor.createComponent(this.mergedConfig.controlErrorComponent); + this.ref ??= this.resolveAnchor().createComponent(this.mergedConfig.controlErrorComponent); const instance = this.ref.instance; if (this.controlErrorsTpl) { @@ -175,7 +173,7 @@ export class ControlErrorsDirective implements OnInit, OnDestroy { if (!this.controlErrorAnchor && this.mergedConfig.controlErrorComponentAnchorFn) { this.customAnchorDestroyFn = this.mergedConfig.controlErrorComponentAnchorFn( this.host, - (this.ref.hostView as EmbeddedViewRef).rootNodes[0] as HTMLElement + (this.ref.hostView as EmbeddedViewRef).rootNodes[0] as HTMLElement, ); } }