Skip to content

Commit ee47d94

Browse files
committed
feat(IgxSnackbar): allow to pass message to show method #7156
1 parent 27d5558 commit ee47d94

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

projects/igniteui-angular/src/lib/snackbar/snackbar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="igx-snackbar" *ngIf="isVisible" (@slideInOut.start)="snackbarAnimationStarted($event)" (@slideInOut.done)="snackbarAnimationDone($event)"
22
[@slideInOut]="isVisible">
33
<div class="igx-snackbar__message" [@fadeInOut]="isVisible">
4-
{{ message }}
4+
{{ snackbarMessage }}
55
<ng-content></ng-content>
66
</div>
77
<button class="igx-snackbar__button" igxRipple="white" *ngIf="actionText" [@fadeInOut] (click)="triggerAction()">

projects/igniteui-angular/src/lib/snackbar/snackbar.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Output
1616
} from '@angular/core';
1717
import { fadeIn, fadeOut, slideInBottom, slideOutBottom } from '../animations/main';
18+
import { DeprecateProperty } from '../core/deprecateDecorators';
1819

1920
let NEXT_ID = 0;
2021
/**
@@ -101,6 +102,7 @@ export class IgxSnackbarComponent {
101102
@HostBinding('attr.id')
102103
@Input()
103104
public id = `igx-snackbar-${NEXT_ID++}`;
105+
104106
/**
105107
* Sets/gets the `message` attribute.
106108
* ```html
@@ -110,7 +112,15 @@ export class IgxSnackbarComponent {
110112
* let message = this.snackbar.message;
111113
* ```
112114
*/
113-
@Input() public message: string;
115+
@DeprecateProperty(`'message' property is deprecated.
116+
You can use place the message in the snackbar content or pass a message parameter to the show method instead.`)
117+
@Input()
118+
public set message(value: string) {
119+
this.snackbarMessage = value;
120+
}
121+
public get message() {
122+
return this.snackbarMessage;
123+
}
114124

115125
/**
116126
* Enables/Disables the visibility of the snackbar.
@@ -182,6 +192,13 @@ export class IgxSnackbarComponent {
182192
* ```
183193
*/
184194
@Output() public animationDone = new EventEmitter<AnimationEvent>();
195+
196+
/**
197+
* @hidden
198+
* @internal
199+
*/
200+
snackbarMessage = '';
201+
185202
/**
186203
* @hidden
187204
*/
@@ -195,8 +212,9 @@ export class IgxSnackbarComponent {
195212
* this.snackbar.show();
196213
* ```
197214
*/
198-
public show(): void {
215+
public show(msg?: string): void {
199216
clearTimeout(this.timeoutId);
217+
if (msg !== undefined) { this.snackbarMessage = msg; }
200218
setTimeout(this.timeoutId);
201219
this.isVisible = true;
202220

0 commit comments

Comments
 (0)