primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Life property to Messages components

Open comlabmohan opened this issue 8 years ago • 8 comments

I'm submitting a new feature request ...

Current behavior

Currently messages doesn't have auto disposable option with time seconds

Expected behavior

<p-messages [(value)]="msgs" [life]="1000" >

What is the motivation / use case for changing the behavior?

Having the requirement to display a messages with auto disposable after some time interval.

comlabmohan avatar Jan 19 '18 13:01 comlabmohan

+1 I agree that this should be implemented as well. In most cases, Messages and Growl both have different uses. However the Messages component not having a 'timeout' is rather unfortunate.

@cagataycivici Is this something that could be implemented? Or are you open for the creation of a pull request for this feature?

davisb10 avatar Feb 23 '18 16:02 davisb10

Sounds good to me.

cagataycivici avatar Mar 26 '18 15:03 cagataycivici

+1

TheParad0X avatar Apr 26 '18 12:04 TheParad0X

+1

klaro00 avatar Apr 26 '18 12:04 klaro00

+1

nitishnaidi avatar Aug 27 '19 16:08 nitishnaidi

Doublicate of #3232 . Maybe should be rejected according to p-toast #7139 @yigitfindikli .

Rotzbua avatar Dec 21 '19 16:12 Rotzbua

It looks like there hasn't been any movement on this for awhile. I went ahead and created a directive to implement this functionality for my own project.

import { AfterContentInit, Directive, OnDestroy } from '@angular/core';
import { Message } from 'primeng/api';
import { Messages } from 'primeng/messages';
import { Subscription } from 'rxjs';

@Directive({
	selector: 'p-messages[enableLife]'
})
export class PrimeMessagesLifeDirective implements AfterContentInit, OnDestroy {
	private msgSub: Subscription;

	constructor(private host: Messages) {}

	ngOnDestroy(): void {
		this.msgSub?.unsubscribe();
	}

	ngAfterContentInit(): void {
		if (this.host.messageService && this.host.enableService && !this.host.contentTemplate) {
			this.msgSub = this.host.messageService.messageObserver.subscribe((messages) => {
				if (!messages) { return; }

				if (messages instanceof Array) {
					messages.map(this.processMessages);
				} else {
					this.processMessages(messages);
				}
			});
		}
	}

	private processMessages(message: Message) {
		if (!message.life) { return; }

		setTimeout(() => {
			const index = this.host.value?.indexOf(message) ?? -1;
			if (index !== -1) {
				this.host.removeMessage(index);
				this.host.cd.markForCheck();
			}
		}, message.life);
	}
}
<p-messages enableLife></p-messages>

Hope this helps anyone wanting life on Messages. 😊

RedSerenity avatar Sep 13 '21 21:09 RedSerenity

Duplicate of https://github.com/primefaces/primeng/issues/3232

yigitfindikli avatar Feb 03 '22 12:02 yigitfindikli