I am calling a modal from another component and the problem is I can only get it to open as small, not as large
comp1.html
<button type="button" class="btn btn-outline-primary btn-lg" (click)="openModal()">Upload
comp1.ts
import {modalComponent} from '../pages/modals/new-modal';
private modalService: BsModalService
constructor(private modalService: BsModalService)
openModal() {
this.bsModalRef = this.modalService.show(modalComponent);
}
modal.component.ts
constructor(private modalService: BsModalService, public bsModalRef: BsModalRef)
modal.html
<div bsModal #newModal="bs-modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
</div>
</div>
</div>
Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.
modal-body use calc() function to calculate desired height. In above case we want to occupy 80vh of the viewport, reduced by the size of header + footer in pixels. This is around 140px together but you can measure it easily and apply your own custom values. For smaller/taller modal modify 80vh accordingly.
Add . modal-dialog-centered to . modal-dialog to vertically center the modal.
Try like this :
openModal() {
this.bsModalRef = this.modalService.show(modalComponent, { class: 'modal-lg' });
}
If you want to pass data to modal component while opening modal,
openModal() {
const initialState = {
data:"Test data"
}
this.bsModalRef = this.modalService.show(modalComponent, {initialState, class: 'modal-lg'});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With