Topic: Open Modal Programmatically
Sam Mallabone asked 7 years ago
Damian Gemza staff answered 7 years ago
<button type="button" class="btn btn-primary relative waves-light" (click)="showModal()" mdbRippleRadius>Launch demo modal</button> <div mdbModal #basicModal="mdb-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myBasicModalLabel" aria-hidden="true" [config]="{backdrop: false, ignoreBackdropClick: true}"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <butto ntype="button" class="close pull-right" aria-label="Close" (click)="basicModal.hide()"> <spanaria-hidden="true">×</span> </button> <h4 class="modal-title w-100" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary waves-light" aria-label="Close" (click)="basicModal.hide()" mdbRippleRadius>Close</button> <button type="button" class="btn btn-primary relative waves-light"mdbRippleRadius>Save changes</button> </div> </div> </div> </div>
import { Component, OnInit, ViewChild } from '@angular/core'; import { ModalDirective } from 'ng-mdb-pro/free/modals/modal.directive'; @Component({ selector:'app-root', templateUrl:'./app.component.html', styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { @ViewChild('basicModal') public showModalOnClick: ModalDirective; public showModal():void { this.showModalOnClick.show(); } ngOnInit() { } }
xfadop pro commented 7 years ago
I had similar requirement and It helped me Damian. Thank You!xzesstence pro answered 6 years ago
import { ModalDirective } from 'ng-uikit-pro-standard'; import { Component, OnInit, ViewChild, Input } from '@angular/core'; @Component({ selector: 'app-modal-dialog', templateUrl: './modal-dialog.component.html', styleUrls: ['./modal-dialog.component.scss'], exportAs: 'child' }) export class ModalDialogComponent implements OnInit { @Input() DialogTitle: string; @Input() DialogBody: string; @Input() DialogOkButtonText: string; @ViewChild('processingModal') processingModal: ModalDirective; constructor() { } ngOnInit() { } openDialog() { this.processingModal.show(); } closeDialog() { this.processingModal.hide(); } } <div mdbModal #processingModal="mdbModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myBasicModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close pull-right" aria-label="Close" (click)="processingModal.hide()"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title w-100" id="myModalLabel">{{DialogTitle}}</h4> </div> <div class="modal-body"> {{DialogBody}} </div> <div class="modal-footer"> <button type="button" mdbBtn color="primary" class="relative waves-light" mdbWavesEffect (click)="processingModal.hide()">{{DialogOkButtonText}}</button> </div> </div> </div> </div> <app-modal-dialog #modal="child" [DialogTitle]="'Dies ist der Titel'" [DialogOkButtonText]="'Dialog schliessen'" [DialogBody]="'Hier steht nichts'"></app-modal-dialog> <a (click)="modal.openDialog()" class="btn btn-primary waves-light" mdbWavesEffect i18n><fa-icon [icon]="faSearch"></fa-icon>Produkt auswählen</a>
Arkadiusz Idzikowski staff answered 6 years ago
ffdev commented 6 years ago
Do you have an eta for when dynamic and reusable modals are available? This is a quite critical feature for bootstrap applications. We use active modals heavily in several projects..
Arkadiusz Idzikowski staff commented 6 years ago
It should be available in next version (December 10).
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: No
- Provided link: No