mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
* [ADF-4811] - added extra method to open snackbar with interpolate args for translated messages * [ADF-4811] - added extra parameter to show info * [ADF-4811] - added extra parameter to show info * [ADF-4811] added review changes
119 lines
5.0 KiB
Markdown
119 lines
5.0 KiB
Markdown
---
|
|
Title: Notification Service
|
|
Added: v2.0.0
|
|
Status: Active
|
|
Last reviewed: 2018-06-08
|
|
---
|
|
|
|
# [Notification Service](../../../lib/core/services/notification.service.ts "Defined in notification.service.ts")
|
|
|
|
Shows a notification message with optional feedback.
|
|
|
|

|
|
|
|
## Class members
|
|
|
|
### Methods
|
|
|
|
- **dismissSnackMessageAction**()<br/>
|
|
dismiss the notification snackbar
|
|
- **openSnackMessage**(message: `string`, config?: `number|MatSnackBarConfig`): [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>`<br/>
|
|
Opens a SnackBar notification to show a message.
|
|
- _message:_ `string` - The message (or resource key) to show.
|
|
- _config:_ `number|MatSnackBarConfig` - (Optional) Time before notification disappears after being shown or MatSnackBarConfig object
|
|
- translationArgs: `any` - The object with the keys for the interpolation of your translation string
|
|
- **Returns** [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>` - Information/control object for the SnackBar
|
|
- **openSnackMessageAction**(message: `string`, action: `string`, config?: `number|MatSnackBarConfig`): [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>`<br/>
|
|
Opens a SnackBar notification with a message and a response button.
|
|
- _message:_ `string` - The message (or resource key) to show.
|
|
- _action:_ `string` - Caption for the response button
|
|
- _config:_ `number|MatSnackBarConfig` - (Optional) Time before notification disappears after being shown or MatSnackBarConfig object
|
|
- **Returns** [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>` - Information/control object for the SnackBar
|
|
- **showError**(message: `string`, action?: `string`): [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>`<br/>
|
|
Rase error message
|
|
- _message:_ `string` - Text message or translation key for the message.
|
|
- _action:_ `string` - (Optional) Action name
|
|
- **Returns** [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>` -
|
|
- **showInfo**(message: `string`, action?: `string`): [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>`<br/>
|
|
Rase info message
|
|
- _message:_ `string` - Text message or translation key for the message.
|
|
- _action:_ `string` - (Optional) Action name
|
|
- **Returns** [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>` -
|
|
- **showWarning**(message: `string`, action?: `string`): [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>`<br/>
|
|
Rase warning message
|
|
- _message:_ `string` - Text message or translation key for the message.
|
|
- _action:_ `string` - (Optional) Action name
|
|
- **Returns** [`MatSnackBarRef`](https://material.angular.io/components/snack-bar/overview)`<any>` -
|
|
|
|
## Details
|
|
|
|
The [Notification Service](notification.service.md) is implemented on top of the Angular Material Design snackbar.
|
|
Use this service to show a notification message, and optionally get feedback from it.
|
|
|
|
```ts
|
|
import { NotificationService } from '@alfresco/adf-core';
|
|
|
|
export class MyComponent implements OnInit {
|
|
|
|
constructor(private notificationService: NotificationService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.notificationService
|
|
.openSnackMessage('test', 200000)
|
|
.afterDismissed()
|
|
.subscribe(() => {
|
|
console.log('The snack-bar was dismissed');
|
|
});
|
|
}
|
|
}
|
|
```
|
|
|
|
```ts
|
|
import { NotificationService } from '@alfresco/adf-core';
|
|
|
|
export class MyComponent implements OnInit {
|
|
|
|
constructor(private notificationService: NotificationService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.notificationService
|
|
.openSnackMessageAction('Do you want to report this issue?', 'send', 200000)
|
|
.afterDismissed()
|
|
.subscribe(() => {
|
|
console.log('The snack-bar was dismissed');
|
|
});
|
|
}
|
|
}
|
|
```
|
|
|
|
```ts
|
|
import { NotificationService } from '@alfresco/adf-core';
|
|
import { MatSnackBarConfig } from '@angular/material';
|
|
|
|
export class MyComponent implements OnInit {
|
|
|
|
snackBarConfig: MatSnackBarConfig = new MatSnackBarConfig();
|
|
|
|
constructor(private notificationService: NotificationService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.notificationService
|
|
.openSnackMessageAction('Do you want to report this issue?', 'send', snackBarConfig)
|
|
.afterDismissed()
|
|
.subscribe(() => {
|
|
console.log('The snack-bar was dismissed');
|
|
});
|
|
}
|
|
}
|
|
```
|
|
|
|
The default message duration is 5000 ms that is used only if you don't pass a custom duration in the parameters of openSnackMessageAction/openSnackMessage methods.
|
|
You can also change the default 5000 ms adding the following configuration in the app.config.json:
|
|
|
|
```json
|
|
"notificationDefaultDuration" : "7000"
|
|
```
|