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

Уведомления

PrimeNG/Toast (opens in a new tab)

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

С чего начать

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

import { ToastModule } from 'primeng/toast';

В .ts файле

import { Component, OnInit } from '@angular/core';
import { MessageService } from 'primeng/api';
 
@Component({
  selector: 'app-prime-toast',
  templateUrl: './prime-toast.component.html',
  styleUrls: ['./prime-toast.component.scss'],
  providers: [MessageService]
})
export class PrimeToastComponent implements OnInit {
 
  constructor(private messageService: MessageService) { }
 
  showSuccess() {
    this.messageService.add({ severity: 'success', summary: 'Success', detail: 'Message Content' });
  }
 
  showInfo() {
    this.messageService.add({ severity: 'info', summary: 'Info', detail: 'Message Content' });
  }
 
  showWarn() {
    this.messageService.add({ severity: 'warn', summary: 'Warn', detail: 'Message Content' });
  }
 
  showError() {
    this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Message Content' });
  }
 
  showCustom() {
    this.messageService.add({ severity: 'custom', summary: 'Custom', detail: 'Message Content', icon: 'pi-file' });
  }
 
  showTopLeft() {
    this.messageService.add({ key: 'tl', severity: 'info', summary: 'Info', detail: 'Message Content' });
  }
 
  showTopCenter() {
    this.messageService.add({ key: 'tc', severity: 'warn', summary: 'Warn', detail: 'Message Content' });
  }
 
  showBottomCenter() {
    this.messageService.add({ key: 'bc', severity: 'success', summary: 'Success', detail: 'Message Content' });
  }
 
  showConfirm() {
    this.messageService.clear();
    this.messageService.add({ key: 'c', sticky: true, severity: 'warn', summary: 'Are you sure?', detail: 'Confirm to proceed' });
  }
 
  showMultiple() {
    this.messageService.addAll([
      { severity: 'success', summary: 'Message 1', detail: 'Message Content' },
      { severity: 'info', summary: 'Message 2', detail: 'Message Content' },
      { severity: 'warn', summary: 'Message 3', detail: 'Message Content' }
    ]);
  }
 
  showSticky() {
    this.messageService.add({ severity: 'info', summary: 'Sticky', detail: 'Message Content', sticky: true });
  }
 
  onConfirm() {
    this.messageService.clear('c');
  }
 
  onReject() {
    this.messageService.clear('c');
  }
 
  clear() {
    this.messageService.clear();
  }
 
  ngOnInit(): void {
  }
}

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

Размещение кода

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

Severities

Positions

Multiple

Clear

Template

Свойства

NameTypeDefaultDescription
keystringnullKey to match the key of a message to display.
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
positionstringtop-rightPosition of the component, valid values are "top-right", "top-left", "bottom-left", "bottom-right", "top-center, "bottom-center" and "center".
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.
showTransitionOptionsstring300ms ease-outTransition options of the show animation.
hideTransitionOptionsstring250ms ease-inTransition options of the hide animation.
showTransformOptionsstringtranslateY(100%)Transform options of the show animation.
hideTransformOptionsstringtranslateY(-100%)Transform options of the hide animation.
preventOpenDuplicatesbooleanfalseIt does not add the new message if there is already a toast displayed with the same content
breakpointsobjectnullObject literal to define styles per screen size.
preventDuplicatesbooleanfalseDisplays only once a message with the same content.

События

NameParametersDescription
onCloseevent.message: Removed messageCallback to invoke when a message is closed.

Шаблоны

NameParameters
message-

Стилизация

NameElement
p-toastMain container element.
p-toast-messageContainer of a message item.
p-toast-icon-closeClose icon of a message.
p-toast-iconSeverity icon.
p-toast-message-contentContainer of message texts.
p-toast-titleSummary of the message.
p-toast-titleDetail of the message.