Feedback - Toast Notifications | Crossroads Digital Design Kit
UI COMPONENTS
ATOMS
FEEDBACK
UI Components / Feedback
Toast Notifications
Toast Notifications requires the inclusion of ng2-toastr, an external resource used to create Toast Notifications in Angular 2 applications.
Below is a simple Angular 4.1.2 app providing buttons to trigger each of the five toast notification options.
The most important piece to remember is that ng2-toastr requires importing BrowserAnimationsModule into the module making using of the library (for Angular 4 apps).
import{Component,ViewContainerRef}from'@angular/core';import{ToastsManager}from'ng2-toastr/ng2-toastr';@Component({selector:'app-root',templateUrl:'./component.html'})exportclassAppComponent{constructor(privatetoastr:ToastsManager,vRef:ViewContainerRef){this.toastr.setRootViewContainerRef(vRef);}showToast(toastType){letoptions={toastLife:10000},message='I am a toast notitification with a very, very, very long message!';switch(toastType){case'success':this.toastr.success(message,'Success!',options);break;case'error':this.toastr.error(message,'Error!',options);break;case'warning':this.toastr.warning(message,'Warning!',options);break;case'info':this.toastr.info(message,'Info!',options);break;case'custom':this.toastr.custom(message,'Custom!',options);break;}returntrue;}}
import { Component, ViewContainerRef } from '@angular/core';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
@Component({
selector: 'app-root',
templateUrl: './component.html'
})
export class AppComponent {
constructor(private toastr: ToastsManager, vRef: ViewContainerRef) {
this.toastr.setRootViewContainerRef(vRef);
}
showToast(toastType) {
let options = { toastLife: 10000 },
message = 'I am a toast notitification with a very, very, very long message!';
switch (toastType) {
case 'success':
this.toastr.success(message, 'Success!', options);
break;
case 'error':
this.toastr.error(message, 'Error!', options);
break;
case 'warning':
this.toastr.warning(message, 'Warning!', options);
break;
case 'info':
this.toastr.info(message, 'Info!', options);
break;
case 'custom':
this.toastr.custom(message, 'Custom!', options);
break;
}
return true;
}
}