Gives new functionality to Angular 9+, generates beautiful popups, dialogs, ConfirmBoxes, AlertBoxes, ToastNotifications. Also gives the ability of opening dynamic components directly from typescript!
Use this popup generator to easily generate beautiful, highly scalable popups. From regular Angular component it renders dynamic component view in popup directly from typescript, including toast notifications, alert box or confirm box.
- Well documented: Extremely simple to use - just follow the tutorials and API documentation!
- Powerful: It uses Angular factory features - generates any component anywhere in popup without HTML selector!
- Awesome: The tool you don't know you needed before!
➤ External links
➤ Table of Contents
➤ Installation
Install the library with:
npm install @costlydeveloper/ngx-awesome-popup
Then import it in your AppModule
:
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppComponent} from './app.component';
import {ConfirmBoxConfigModule, DialogConfigModule, NgxAwesomePopupModule, ToastNotificationConfigModule} from '@costlydeveloper/ngx-awesome-popup';
@NgModule({
declarations: [
AppComponent
],
imports : [
BrowserModule,
NgxAwesomePopupModule.forRoot(),
DialogConfigModule.forRoot(),
ConfirmBoxConfigModule.forRoot(),
ToastNotificationConfigModule.forRoot()
],
providers : [],
bootstrap : [AppComponent]
})
export class AppModule {
}
API documentation:
➤ Usage
Check The API Documentation for more advance setup.
Toast Notification
Simply open toast notification from any component or any custom typescript class:
import {Component, OnInit} from '@angular/core';
import {DialogLayoutDisplay, ToastNotificationInitializer} from '@costlydeveloper/ngx-awesome-popup';
@Component({
selector : 'app-root',
templateUrl: './app.component.html',
styleUrls : ['./app.component.scss']
})
export class AppComponent implements OnInit {
ngOnInit() {
this.toastNotification();
}
toastNotification() {
const newToastNotification = new ToastNotificationInitializer();
newToastNotification.setTitle('Warning!');
newToastNotification.setMessage('Form is not valid!');
newToastNotification.setConfig({
LayoutType: DialogLayoutDisplay.WARNING
});
newToastNotification.openToastNotification$();
}
}
API documentation:
Confirm Box / Alert Box
It is very easy to open Confirm Box or Alert Box from any component or any custom typescript class:
import {Component, OnInit} from '@angular/core';
import {DialogLayoutDisplay, ConfirmBoxInitializer} from '@costlydeveloper/ngx-awesome-popup';
@Component({
selector : 'app-root',
templateUrl: './app.component.html',
styleUrls : ['./app.component.scss']
})
export class AppComponent implements OnInit {
ngOnInit() {
this.confirmBox();
}
confirmBox() {
const confirmBox = new ConfirmBoxInitializer();
confirmBox.setTitle('Are you sure?');
confirmBox.setMessage('Confirm to delete user: John Doe!');
confirmBox.setButtonLabels('YES', 'NO');
confirmBox.setConfig({
LayoutType: DialogLayoutDisplay.DANGER
});
const subscription = confirmBox.openConfirmBox$().subscribe(resp => {
console.log('Clicked button response: ', resp);
subscription.unsubscribe();
});
}
}
API documentation:
Open any component in Dialog
Simply open any Angular component from any typescript file without HTML selector.
- Send and receive any data with dialog dynamic component and back.
- Set custom buttons and listen the click event inside dynamic component (AnyAngularComponent)
Setup of evoke of the dialog:
import {Component, OnInit} from '@angular/core';
import {AnyAngularComponent} from './any-angular-component/any-angular.component';
import {DialogLayoutDisplay, DialogInitializer, ButtonLayoutDisplay, ButtonMaker} from '@costlydeveloper/ngx-awesome-popup';
@Component({
selector : 'app-root',
templateUrl: './app.component.html',
styleUrls : ['./app.component.scss']
})
export class AppComponent implements OnInit {
ngOnInit() {
this.dialog();
}
dialog() {
const dialogPopup = new DialogInitializer(AnyAngularComponent);
dialogPopup.setCustomData({name: 'John', surname: 'Doe', id: 1});
dialogPopup.setConfig({
Width : '500px',
LayoutType: DialogLayoutDisplay.NONE
});
dialogPopup.setButtons([
new ButtonMaker('Edit', 'edit', ButtonLayoutDisplay.WARNING),
new ButtonMaker('Submit', 'submit', ButtonLayoutDisplay.SUCCESS),
new ButtonMaker('Cancel', 'cancel', ButtonLayoutDisplay.SECONDARY)
]);
const subscription = dialogPopup.openDialog$().subscribe(resp => {
console.log('dialog response: ', resp);
subscription.unsubscribe();
});
}
}
API documentation:
Setup of child-dynamic component that is rendered in dialog:
The child dynamic component represents AnyAngularComponent from example above.
import { Component, OnInit, OnDestroy } from '@angular/core';
import {Subscription} from 'rxjs';
import {DialogBelonging} from '@costlydeveloper/ngx-awesome-popup';
@Component({
selector: 'app-any-angular-component',
templateUrl: './any-angular.component.html',
styleUrls: ['./any-angular.component.scss']
})
export class AnyAngularComponent implements OnInit, OnDestroy{
subscriptions: Subscription[] = [];
constructor(private dialogBelonging: DialogBelonging) {}
ngOnInit(): void {
console.log(this.dialogBelonging);
this.subscriptions.push(
this.dialogBelonging.EventsController.onButtonClick$.subscribe((_Button) => {
if (_Button.ID === 'edit') {
} else if (_Button.ID === 'submit') {
this.dialogBelonging.EventsController.close();
}
else if (_Button.ID === 'cancel') {
this.dialogBelonging.EventsController.close();
}
})
);
setTimeout(() => {
this.dialogBelonging.EventsController.closeLoader();
}, 1000);
}
ngOnDestroy(): void {
this.subscriptions.forEach(sub => sub.unsubscribe());
}
}
API documentation:
➤ License
Licensed under MIT.