ngn-alert provides you an alert service to convey messages. It has a simple service that can use in your Angular 4+ applications.
npm install ngn-alert
Include ngn-alert module in your module.
import { NgnAlertModule } from 'ngn-alert';
@NgModule({
declarations: [
],
imports: [
NgnAlertModule.forRoot(),
BrowserModule
],
bootstrap: []
})
export class ExampleModule { }
First of import ngn-alert service in your component where you want to use to communicate with ngn-alert API.
import { NgnAlertService } from 'ngn-alert';
Use it on Constructor of the required class
constructor(private ngnAlertService:NgnAlertService){
}
The service provides two functions to Activate and Deactivate alert messages.
- ngnActivate - Activate alert with options.
- ngnDeactivate - Deactivate activated alerts.
export class AppComponent {
title = 'MyApp';
options = {
text:"Success !",
type:"fail",
autoDismis:false,
timeout:2000
}
constructor(private ngnAlertService:NgnAlertService){}
activate(){
this.ngnAlertService.ngnActivate(this.options);
}
}
you can use same for ngnDeactivate()
Deactivate(){
this.ngnAlertService.ngnDeactivate()
}
functions | type | Definition |
---|---|---|
text | String | The text to be displayed in the alert, eg: Success, Fail, Send etc. Make it small to contain the alert box. |
type | String | The type of message. It only accepts certain string values success , fail , warning |
autoDismis | Boolean | The alert should dismiss automatically or not. true or false |
timeout | Number (in milliseconds) | If you have set autoDismis=true , then you can set time a for auto dismiss.Default is 2 seconds (2000 ms) |