Компоненты PrimeNG
Confirmdialog

Подтверждающее диалоговое окно

PrimeNG/ConfirmDialog (opens in a new tab)

Диалоговое окно подтверждения поддерживается службой, использующей наблюдаемые объекты для простого отображения окон подтверждения, которые могут совместно использоваться несколькими действиями в одном компоненте.

С чего начать

Подключите модуль

import { ConfirmDialogModule } from 'primeng/confirmdialog';

В .ts файле

import { Component, OnInit } from '@angular/core';
import { ConfirmationService } from 'primeng/api';
import { Message } from 'primeng/api';
import { PrimeNGConfig } from 'primeng/api';
import { MessageService} from 'primeng/api';
 
@Component({
  selector: 'app-prime-confirmdialog',
  templateUrl: './prime-confirmdialog.component.html',
  styleUrls: ['./prime-confirmdialog.component.scss'],
  providers: [ConfirmationService, MessageService]
})
export class PrimeConfirmdialogComponent implements OnInit {
 
  msgs: Message[] = [];
  position = '';
 
  constructor(private confirmationService: ConfirmationService, private primengConfig: PrimeNGConfig, private messageService: MessageService) { }
 
  ngOnInit(): void {
    this.primengConfig.ripple = true;
  }
 
  confirm1() {
    this.confirmationService.confirm({
      message: 'Are you sure that you want to proceed?',
      header: 'Confirmation',
      icon: 'pi pi-exclamation-triangle',
      accept: () => {
        this.msgs = [{ severity: 'info', summary: 'Confirmed', detail: 'You have accepted' }];
      },
      reject: () => {
        this.msgs = [{ severity: 'info', summary: 'Rejected', detail: 'You have rejected' }];
      }
    });
  }
 
  confirm2() {
    this.confirmationService.confirm({
      message: 'Do you want to delete this record?',
      header: 'Delete Confirmation',
      icon: 'pi pi-info-circle',
      accept: () => {
        this.msgs = [{ severity: 'info', summary: 'Confirmed', detail: 'Record deleted' }];
      },
      reject: () => {
        this.msgs = [{ severity: 'info', summary: 'Rejected', detail: 'You have rejected' }];
      }
    });
  }
 
  confirmPosition(position: string) {
    this.position = position;
 
    this.confirmationService.confirm({
      message: 'Do you want to delete this record?',
      header: 'Delete Confirmation',
      icon: 'pi pi-info-circle',
      accept: () => {
        this.msgs = [{ severity: 'info', summary: 'Confirmed', detail: 'Record deleted' }];
      },
      reject: () => {
        this.msgs = [{ severity: 'info', summary: 'Rejected', detail: 'You have rejected' }];
      },
      key: 'positionDialog'
    });
  }
 
}

Встройте компонент с помощью тэга p-confirmDialog.

Для отображения всплывающих сообщений разместите в теле страницы следующий код:.

Basic

Position

Свойства

NameTypeDefaultDescription
headerstringnullTitle text of the dialog.
messagestringnullMessage of the confirmation.
keystringnullOptional key to match the key of confirm object, necessary to use when component tree has multiple confirm dialogs.
iconstringnullIcon to display next to message.
acceptLabelstringYesLabel of the accept button.
acceptAriaLabelstringnullDefines a string that labels the accept button for accessibility.
acceptIconstringpi pi-checkIcon of the accept button.
acceptVisiblebooleantrueVisibility of the accept button.
rejectLabelstringNoLabel of the reject button.
rejectAriaLabelstringnullDefines a string that labels the reject button for accessibility.
rejectIconstringpi pi-timesIcon of the reject button.
rejectVisiblebooleantrueVisibility of the reject button.
closeOnEscapebooleantrueSpecifies if pressing escape key should hide the dialog.
dismissableMaskbooleanfalseSpecifices if clicking the modal background should hide the dialog.
rtlbooleanfalseWhen enabled dialog is displayed in RTL direction.
closablebooleantrueAdds a close icon to the header to hide the dialog.
focusTrapbooleantrueWhen enabled, can only focus on elements inside the confirm dialog.
appendToanynullTarget element to attach the dialog, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
acceptButtonStyleClassstringp-confirmdialog-acceptbuttonStyle class of the accept button.
rejectButtonStyleClassstringp-confirmdialog-rejectbuttonStyle class of the reject button.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.
breakpointsobjectnullObject literal to define widths per screen size.
transitionOptionsstring400ms cubic-bezier(0.25, 0.8, 0.25, 1)Transition options of the animation.
defaultFocusstringacceptElement to receive the focus when the dialog gets visible, valid values are "accept", "reject", "close" and "none".

Шаблоны

NameParameters
header-
footer-

Стилизация

NameElement
p-dialogContainer element
p-confirmdialogContainer element
p-dialog-titlebarContainer of header.
p-dialog-titleHeader element.
p-dialog-titlebar-iconIcon container inside header.
p-dialog-titlebar-closeClose icon element.
p-dialog-contentContent element.