Подтверждающее диалоговое окно
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
Свойства
Name | Type | Default | Description |
---|---|---|---|
header | string | null | Title text of the dialog. |
message | string | null | Message of the confirmation. |
key | string | null | Optional key to match the key of confirm object, necessary to use when component tree has multiple confirm dialogs. |
icon | string | null | Icon to display next to message. |
acceptLabel | string | Yes | Label of the accept button. |
acceptAriaLabel | string | null | Defines a string that labels the accept button for accessibility. |
acceptIcon | string | pi pi-check | Icon of the accept button. |
acceptVisible | boolean | true | Visibility of the accept button. |
rejectLabel | string | No | Label of the reject button. |
rejectAriaLabel | string | null | Defines a string that labels the reject button for accessibility. |
rejectIcon | string | pi pi-times | Icon of the reject button. |
rejectVisible | boolean | true | Visibility of the reject button. |
closeOnEscape | boolean | true | Specifies if pressing escape key should hide the dialog. |
dismissableMask | boolean | false | Specifices if clicking the modal background should hide the dialog. |
rtl | boolean | false | When enabled dialog is displayed in RTL direction. |
closable | boolean | true | Adds a close icon to the header to hide the dialog. |
focusTrap | boolean | true | When enabled, can only focus on elements inside the confirm dialog. |
appendTo | any | null | Target 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). |
acceptButtonStyleClass | string | p-confirmdialog-acceptbutton | Style class of the accept button. |
rejectButtonStyleClass | string | p-confirmdialog-rejectbutton | Style class of the reject button. |
baseZIndex | number | 0 | Base zIndex value to use in layering. |
autoZIndex | boolean | true | Whether to automatically manage layering. |
breakpoints | object | null | Object literal to define widths per screen size. |
transitionOptions | string | 400ms cubic-bezier(0.25, 0.8, 0.25, 1) | Transition options of the animation. |
defaultFocus | string | accept | Element to receive the focus when the dialog gets visible, valid values are "accept", "reject", "close" and "none". |
Шаблоны
Name | Parameters |
---|---|
header | - |
footer | - |
Стилизация
Name | Element |
---|---|
p-dialog | Container element |
p-confirmdialog | Container element |
p-dialog-titlebar | Container of header. |
p-dialog-title | Header element. |
p-dialog-titlebar-icon | Icon container inside header. |
p-dialog-titlebar-close | Close icon element. |
p-dialog-content | Content element. |