### File

`src/lib/directives/form-loaded.directive.ts`

### Implements

`AfterViewInit` `OnDestroy`

### Metadata

Selector | `[rxapFormLoaded]`
Standalone | `true`

### Constructor

`constructor(formDirective: FormDirective, template: TemplateRef, viewContainerRef: ViewContainerRef)`
Defined in src/lib/directives/form-loaded.directive.ts:22
Parameters :
Name | Type | Optional
formDirective | `FormDirective` | No
template | `TemplateRef<void>` | No
viewContainerRef | `ViewContainerRef` | No

    import {
      AfterViewInit,
      Directive,
      Inject,
      OnDestroy,
      TemplateRef,
      ViewContainerRef,
    } from '@angular/core';
    import { FormDirective } from './form.directive';
    import { Subscription } from 'rxjs';
    import {
      distinctUntilChanged,
      tap,
    } from 'rxjs/operators';

    @Directive({
      selector: '[rxapFormLoaded]',
      standalone: true,
    })
    export class FormLoadedDirective implements AfterViewInit, OnDestroy {

      private subscription?: Subscription;

      constructor(
        @Inject(FormDirective) private readonly formDirective: FormDirective,
        @Inject(TemplateRef) private readonly template: TemplateRef<void>,
        @Inject(ViewContainerRef) private readonly viewContainerRef: ViewContainerRef,
      ) {
      }

      public ngAfterViewInit() {
        this.subscription = this.formDirective.loaded$.pipe(
          distinctUntilChanged(),
          tap(loading => {
            this.viewContainerRef.clear();
            if (loading) {
              this.viewContainerRef.createEmbeddedView(this.template);
            }
          }),
        ).subscribe();
      }

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

    }

# results matching ""

# No results matching ""