Alert Service
The Alert Service (AlertService
) provides the ability to show alerts of different types to the user. Alerts appear in the accompanying cloudapp-alert
component. (The AlertService is available from version 0.2.0 of the Cloud Apps SDK).
The following setup is required, and is added by default to a new Cloud App when created:
app.module.ts
import { AlertModule } from '@exlibris/exl-cloudapp-angular-lib'; @NgModule({ ... imports: [ ... AlertModule, ], }) export class AppModule { }
app.component.ts
import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: '<cloudapp-alert></cloudapp-alert><router-outlet></router-outlet>' }) export class AppComponent { constructor() { } }
The following methods are available:
success
This method is used to send a success message.
Interface
success(message: string, options?: Partial<Alert>)
Parameters:
- message: the message to be displayed
- options: partial
Alert
object
Example
import { AlertService } from '@exlibris/exl-cloudapp-angular-lib'; export class MainComponent implements OnInit { constructor( private alert: AlertService ) { } ngOnInit() { this.alert.success('This is a success message'); this.alert.success('This is a persistent success message', { autoClose: false }); } }
info
This method is used to send an info message.
Interface
info(message: string, options?: Partial<Alert>)
Parameters:
- message: the message to be displayed
- options: partial
Alert
object
warning
This method is used to send a warning message.
Interface
warning(message: string, options?: Partial<Alert>)
Parameters:
- message: the message to be displayed
- options: partial
Alert
object
error
This method is used to send an error message.
Interface
error(message: string, options?: Partial<Alert>)
Parameters:
- message: the message to be displayed
- options: partial
Alert
object
clear
This method is used to clear all alerts.
Interface
clear()
Interfaces
Alert
Properties:
autoClose: boolean
, whether the alert should be closed automaticallykeepAfterRouteChange: boolean
, whether the alert should be kept after route change, default falsedelay: number
, time in milliseconds to wait before alert is closed (ifautoClose
is true), default 3000 (from CLI version 0.3.0)