### File

`src/lib/directives/array/form-array-add-item-button.directive.ts`

### Implements

`AfterViewInit` `OnDestroy`

### Metadata

Selector | `[rxapFormArrayItemAddButton]`
Standalone | `true`

### Index

###### Properties

- Protected formArray
- type

###### Methods

- Protected onClick

###### HostBindings

- disabled
- type

###### HostListeners

- click

###### Accessors

- disabled
- isDisabled

### Constructor

`constructor(parent: ControlContainer, matButton: MatButton)`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:28

Parameters :

Name | Type | Optional
parent | `ControlContainer` | No
matButton | `MatButton` | No

### HostBindings

disabled
Type : `boolean`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:37

type
Type : `string`
Default value : `'button'`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:26

### HostListeners

click
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:61

### Methods

Protected onClick
`onClick()`
Decorators : `@HostListener('click')`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:61
Returns : `void`

### Properties

Protected formArray
Type : `RxapFormArray`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:27

type
Type : `string`
Default value : `'button'`
Decorators : `@HostBinding('type')`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:26

### Accessors

disabled
get `disabled()`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:37

isDisabled
get `isDisabled()`
Defined in src/lib/directives/array/form-array-add-item-button.directive.ts:41

    import {
      AfterViewInit,
      Directive,
      HostBinding,
      HostListener,
      OnDestroy,
      Optional,
      SkipSelf,
    } from '@angular/core';
    import { ControlContainer } from '@angular/forms';
    import { MatButton } from '@angular/material/button';
    import { RxapFormArray } from '@rxap/forms';
    import {
      Subscription,
      tap,
    } from 'rxjs';

    // TODO : move to rxap packages
    @Directive({
      selector: '[rxapFormArrayItemAddButton]',
      standalone: true,
    })
    export class FormArrayAddItemButtonDirective implements AfterViewInit, OnDestroy {

      @HostBinding('type')
      type = 'button';
      protected formArray!: RxapFormArray;
      private _controlDisabledSubscription?: Subscription;

      constructor(
        @Optional() @SkipSelf() protected readonly parent: ControlContainer,
        @Optional() protected readonly matButton: MatButton,
      ) {
      }

      @HostBinding('disabled')
      get disabled() {
        return this.isDisabled;
      }

      protected get isDisabled(): boolean {
        return !!this.formArray?.disabled;
      }

      ngAfterViewInit() {
        if (this.parent.control instanceof RxapFormArray) {
          this.formArray = this.parent.control;
        }
        if (this.matButton) {
          this._controlDisabledSubscription = this.formArray.disabled$.pipe(
            tap(isDisabled => this.matButton.disabled = isDisabled),
          ).subscribe();
        }
      }

      ngOnDestroy() {
        this._controlDisabledSubscription?.unsubscribe();
      }

      @HostListener('click')
      protected onClick() {
        this.formArray.insertAt();
      }

    }

# results matching ""

# No results matching ""