File

src/app/shared/components/forms/abstract-form-component.ts

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(dialogService: NbDialogService)
Parameters :
Name Type Optional
dialogService NbDialogService No

Properties

formGroup
Type : FormGroup

Methods

onCancel
onCancel()
Returns : void

Inputs

cancelButtonName
Type : string
submitButtonName
Type : string

Outputs

cancelled
Type : EventEmitter
import { NbDialogService } from '@nebular/theme';
import { FormGroup } from '@angular/forms';
import { ConfirmDiscardDialogComponent } from '../dialogs/confirm-discard-dialog/confirm-discard-dialog.component';
import { Output, EventEmitter, Input } from '@angular/core';

export abstract class AbstractFormComponent {
  @Input() submitButtonName: string;
  @Input() cancelButtonName: string;
  @Output() cancelled = new EventEmitter<any>();

  formGroup: FormGroup;

  constructor(protected dialogService: NbDialogService) {}

  onCancel() {
    if (this.formGroup.dirty && this.formGroup.touched) {
      const confirmDiscardComponentRef = this.dialogService.open(ConfirmDiscardDialogComponent, {
        autoFocus: false,
        closeOnBackdropClick: false,
      });

      confirmDiscardComponentRef.componentRef.instance.onDiscardConfirm.subscribe(
        (cancelConfirmed: boolean) => {
          if (cancelConfirmed) {
            this.cancelled.emit();
          }
        },
      );
    } else {
      this.cancelled.emit();
    }
  }
}

result-matching ""

    No results matching ""