File

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

Extends

FormArrayItemButton

Implements

AfterViewInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
HostBindings
HostListeners

Inputs

shouldTemporarilyDeleted
Type : function
Default value : () => false

A function that returns if the control should be temporarily deleted. true - in the given form group the deleted control is set to true false - the form group is removed from the (parent) form array

HostBindings

disabled
Type : boolean
Inherited from FormArrayItemButton
type
Type : string
Default value : 'button'
Inherited from FormArrayItemButton

HostListeners

click

Methods

Protected onClick
onClick()
Decorators :
@HostListener('click')
Inherited from FormArrayItemButton
Returns : void
Protected updateDisplayStyle
updateDisplayStyle()
Inherited from FormArrayItemButton
Returns : void

Properties

Protected deletedControl
Type : RxapFormControl<boolean>
Inherited from FormArrayItemButton
Protected formArray
Type : RxapFormArray
Inherited from FormArrayItemButton
Protected formGroup
Type : RxapFormGroup<literal type>
Inherited from FormArrayItemButton
type
Type : string
Default value : 'button'
Decorators :
@HostBinding('type')
Inherited from FormArrayItemButton
import {
  AfterViewInit,
  Directive,
  HostListener,
  Input,
  OnDestroy,
} from '@angular/core';
import { RxapFormGroup } from '@rxap/forms';
import { FormArrayItemButton } from './form-array-item-button';

// TODO : move to rxap packages
@Directive({
  selector: 'button[rxapFormArrayItemRemoveButton]',
  standalone: true,
})
export class FormArrayItemRemoveButtonDirective extends FormArrayItemButton implements AfterViewInit, OnDestroy {

  /**
   * A function that returns if the control should be temporarily deleted.
   * true - in the given form group the deleted control is set to true
   * false - the form group is removed from the (parent) form array
   */
  @Input()
  public shouldTemporarilyDeleted: (formGroup: RxapFormGroup) => boolean = () => false;

  @HostListener('click')
  protected onClick() {
    const templateDelete = this.shouldTemporarilyDeleted(this.formGroup);
    if (templateDelete) {
      this.deletedControl.setValue(true);
    } else {
      this.formArray.removeAt(this.index);
    }
  }

  protected updateDisplayStyle() {
    if (this.isDeleted) {
      this.renderer.setStyle(this.elementRef.nativeElement, 'display', 'none');
    } else {
      this.renderer.removeStyle(this.elementRef.nativeElement, 'display');
    }
  }

}

results matching ""

    No results matching ""