### File

`src/lib/directives/form-control-error.directive.ts`

### Deprecated

removed use the rxapControlError or rxapControlErrors directive

### Implements

`OnInit` `OnDestroy`

### Metadata

Selector | `[rxapFormControlError]`
Standalone | `true`

### Index

###### Inputs
rxapFormControlErrorFrom rxapFormControlErrorIf

### Constructor

`constructor(template: TemplateRef, parent: ControlContainer, viewContainerRef: ViewContainerRef)`
Defined in src/lib/directives/form-control-error.directive.ts:44
Parameters :
Name | Type | Optional
template | `TemplateRef<literal type>` | No
parent | `ControlContainer` | No
viewContainerRef | `ViewContainerRef` | No

### Inputs

rxapFormControlErrorFrom
Type : `string`
Required : true
Defined in src/lib/directives/form-control-error.directive.ts:35

rxapFormControlErrorIf
Type : `string`
Required : true
Defined in src/lib/directives/form-control-error.directive.ts:42

    import {
      Directive,
      Host,
      Input,
      OnDestroy,
      OnInit,
      SkipSelf,
      TemplateRef,
      ViewContainerRef,
    } from '@angular/core';
    import { ValidationErrors } from '../types';
    import { ControlContainer } from '@angular/forms';
    import { Required } from '@rxap/utilities';
    import { Subscription } from 'rxjs';
    import {
      filter,
      startWith,
      tap,
    } from 'rxjs/operators';

    /**
     * @deprecated removed use the rxapControlError or rxapControlErrors directive
     */
    @Directive({
      selector: '[rxapFormControlError]',
      standalone: true,
    })
    export class FormControlErrorDirective implements OnInit, OnDestroy {

      // eslint-disable-next-line @angular-eslint/no-input-rename
      @Input({
        required: true,
        alias: 'rxapFormControlErrorFrom',
      })
      public name!: string;

      // eslint-disable-next-line @angular-eslint/no-input-rename
      @Input({
        required: true,
        alias: 'rxapFormControlErrorIf',
      })
      public errorKey!: string;

      private subscription?: Subscription;

      constructor(
        private readonly template: TemplateRef<{ $implicit: ValidationErrors }>,
        @Host() @SkipSelf() private readonly parent: ControlContainer,
        private readonly viewContainerRef: ViewContainerRef,
      ) {
      }

      public ngOnInit() {
        const control = this.parent.control?.get(this.name);

        if (!control) {
          throw new Error('Could not extract form control instance');
        }

        this.subscription = control.statusChanges.pipe(
          startWith(control.status),
          filter(status => status === 'INVALID'),
          tap(() => {
            this.viewContainerRef.clear();
            if (control.hasError(this.errorKey)) {
              this.viewContainerRef.createEmbeddedView(this.template, { $implicit: control.getError(this.errorKey) });
            }
          }),
        ).subscribe();

      }

      public ngOnDestroy() {
        this.subscription?.unsubscribe();
      }

    }

# results matching ""

# No results matching ""