Last active
December 26, 2017 14:27
-
-
Save netstart/69808a3a78030596007c3bc3b0b2bac7 to your computer and use it in GitHub Desktop.
A little abstraction to use Grow Message component from PrimeNG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injectable} from '@angular/core'; | |
import {MessageService} from 'primeng/components/common/messageservice'; | |
/** | |
* A little abstraction to use Grow Message component from PrimeNG | |
* @see https://www.primefaces.org/primeng/#/growl | |
* | |
* Don't forget to use the tag <p-growl [(value)]="growlMessage" life="5000"></p-growl> | |
* | |
*/ | |
@Injectable() | |
export class GrowMessageService { | |
private SUCCESS = 'success'; | |
private INFO = 'info'; | |
private WARN = 'warn'; | |
private ERROR = 'error'; | |
constructor(private messageService: MessageService) { | |
} | |
addSingleError(summary: string, detail: string) { | |
this.addSingle(this.ERROR, summary, detail); | |
} | |
addSingleWarn(summary: string, detail: string) { | |
this.addSingle(this.WARN, summary, detail); | |
} | |
addSingleInfo(summary: string, detail: string) { | |
this.addSingle(this.INFO, summary, detail); | |
} | |
addSingleSuccess(summary: string, detail: string) { | |
this.addSingle(this.SUCCESS, summary, detail); | |
} | |
addSuccess(detail: string) { | |
this.addSingleSuccess('Sucesso', detail); | |
} | |
private addSingle(severity: string, summary: string, detail: string) { | |
this.messageService.add({severity: severity, summary: summary, detail: detail}); | |
} | |
addMultiple(growMessages: Array<GrowMessage>) { | |
this.messageService.addAll(growMessages); | |
} | |
clear() { | |
this.messageService.clear(); | |
} | |
} | |
export class GrowMessage { | |
constructor(severity: string, summary: string, detail: string) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment