All Projects → zurfyx → angular-custom-modal

zurfyx / angular-custom-modal

Licence: MIT license
Angular2+ Modal / Dialog (with inner component support).

Programming Languages

typescript
32286 projects
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to angular-custom-modal

react-redux-modal-flex
[DEPRECATED] Make easy a modal/popup with Redux
Stars: ✭ 14 (-53.33%)
Mutual labels:  modal, dialog
LSDialogViewController
Custom Dialog for iOS written in Swift
Stars: ✭ 74 (+146.67%)
Mutual labels:  modal, dialog
Nativepopup
Clone of Apple iOS App's feedback popup, and easily customizable.
Stars: ✭ 247 (+723.33%)
Mutual labels:  modal, dialog
Wc Messagebox
基于 Vue 2.0 开发的 Alert, Toast, Confirm 插件, UI仿照 iOS 原生
Stars: ✭ 203 (+576.67%)
Mutual labels:  modal, dialog
react-spring-bottom-sheet
Accessible ♿️, Delightful ✨, & Fast 🚀
Stars: ✭ 604 (+1913.33%)
Mutual labels:  modal, dialog
Jquery Modal
The simplest possible modal for jQuery
Stars: ✭ 2,459 (+8096.67%)
Mutual labels:  modal, dialog
MultiDialog
MultiDialog utilizes jQuery UI Dialog Widget for a full featured Modalbox / Lightbox application.
Stars: ✭ 23 (-23.33%)
Mutual labels:  modal, dialog
Bdialog
Extend the Bootstrap Modal features, making dialog more functions and easier to use, dialog type including modal, alert, mask and toast types
Stars: ✭ 174 (+480%)
Mutual labels:  modal, dialog
react-redux-modals
This repo created for Medium.com: React/Redux: Modals and Dialogs
Stars: ✭ 30 (+0%)
Mutual labels:  modal, dialog
sweet-modal-vue
The sweetest library to happen to modals.
Stars: ✭ 762 (+2440%)
Mutual labels:  modal, dialog
Pmalertcontroller
PMAlertController is a great and customizable alert that can substitute UIAlertController
Stars: ✭ 2,397 (+7890%)
Mutual labels:  modal, dialog
eins-modal
Simple to use modal / alert / dialog / popup. Created with pure JS. No javascript knowledge required! Works on every browser and device! IE9
Stars: ✭ 30 (+0%)
Mutual labels:  modal, dialog
Modali
A delightful modal dialog component for React, built from the ground up to support React Hooks.
Stars: ✭ 183 (+510%)
Mutual labels:  modal, dialog
React Native Simple Dialogs
⚛ Cross-platform React Native dialogs based on the Modal component
Stars: ✭ 218 (+626.67%)
Mutual labels:  modal, dialog
React Modal Hook
Syntactic sugar for handling modals using React Hooks
Stars: ✭ 174 (+480%)
Mutual labels:  modal, dialog
react-st-modal
Simple and flexible modal dialog component for React JS
Stars: ✭ 41 (+36.67%)
Mutual labels:  modal, dialog
Dialog
👻 A simple to use, highly customizable, and powerful modal for Angular Applications
Stars: ✭ 158 (+426.67%)
Mutual labels:  modal, dialog
Ax5ui Kernel
Javascript UI Framework - AX5UI - Kernel Module
Stars: ✭ 164 (+446.67%)
Mutual labels:  modal, dialog
vue-modal
Reusable Modal component, supports own custom HTML, text and classes.
Stars: ✭ 29 (-3.33%)
Mutual labels:  modal, dialog
vue-modal
A customizable, stackable, and lightweight modal component for Vue.
Stars: ✭ 96 (+220%)
Mutual labels:  modal, dialog

Angular Custom Modal

npm Version Build Status

Angular2+ Modal / Dialog (with inner component support).

A continuation of https://stackoverflow.com/a/46949848

Demo

zurfyx.github.io/angular-custom-modal

Install

npm install angular-custom-modal

Features

Core:

Minor:

  • Optional CSS animations
  • Optional parent scrolling when modal is visible
  • Escape or button to close modal

Usage

app.module.ts

imports: [
  ...
  ModalModule,
  ...
],
...
})

Raw HTML

app.component.html

<button (click)="htmlInsideModal.open()">Raw HTML inside modal</button>
<modal #htmlInsideModal>
  <ng-template #modalHeader><h2>HTML inside modal</h2></ng-template>
  <ng-template #modalBody>
    <p>HTML content inside modal</p>
  </ng-template>
</modal>

Component inside Modal

my-component.component.ts

@Component({
  selector: 'app-my-component',
  templateUrl: 'my-component.component.html',
})
export class AppModalContentComponent { }

my-component.component.html

<p>My component's HTML</p>

app.component.html

<button (click)="componentInsideModal.open()">Component inside modal</button>
<modal #componentInsideModal>
  <ng-template #modalHeader><h2>Component inside modal</h2></ng-template>
  <ng-template #modalBody>
    <app-my-component></app-my-component>
  </ng-template>
  <ng-template #modalFooter></ng-template>
</modal>

Nested Modal

app.component.html

<modal #nestedModal>
  <ng-template #modalHeader><h2>Nested modal</h2></ng-template>
  <ng-template #modalBody>
    Nested modals can be created by simply adding a &lt;modal&gt; inside a &lt;modal&gt;
    ...
    <button (click)="nestedModalX.open()">Open nested modal</button>
    <modal #nestedModalX>
      <ng-template #modalBody>This is the nested modal content.</ng-template>
    </modal>
  </ng-template>
</modal>

See example source code for more information.

Why ng-template?

ng-template prevents the parent component from initializing the component. Only when the modal library finds it convenient the component will be initialize and visible to the user. Hence, it preserves the natural ngOnInit() and ngOnDestroy() that we expect.

Similar libraries which make use of <ng-content> and its content transclution strategy, do not prevent the component from initializing, but rather just hide it. The component was already initialized in the parent component.

References:
https://angular.io/api/common/NgTemplateOutlet
https://blog.angular-university.io/angular-ng-template-ng-container-ngtemplateoutlet/
https://medium.com/claritydesignsystem/ng-content-the-hidden-docs-96a29d70d11b
https://netbasal.com/understanding-viewchildren-contentchildren-and-querylist-in-angular-896b0c689f6e

Styles

The library carries the minimum generic styles. Beautifying it is up to you.

Default styles

You can find the demo copy-paste styles in modal.css.

Bootstrap

Bootstrap users require no additional CSS other than the Bootstrap library (either version 3 or 4).

API

ModalComponent

Name Type Description
header @ContentChild('modalHeader'): TemplateRef Angular Template (<ng-template>) to use as header.
body @ContentChild('modalBody'): TemplateRef Angular Template (ng-template) to use as body.
footer @ContentChild('modalFooter'): TemplateRef Angular Template (ng-template) to use as footer.
closeOnOutsideClick @Input(): boolean = true When set to true modal will close when a click is performed outside the modal container.
open () => void Opens the modal.
close () => void Closes the modal.
isTopMost () => boolean Returns true is the modal is the top most modal, or false if it is underneath another modal.

Special thanks

To Stephen Paul for the initial Angular 2 Modal version.

License

MIT © Gerard Rovira Sánchez

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].