Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize NgbModal size

I'm using Angular 6 and NgbModal like

openViewDescriptionModal(id) {
  const viewModal = this.modalService.open(ProductComponent, {size: 'lg'});
}

But this opens modal with width 50% only with 25% space empty on both sides.

I want to redesign modal width to up to 90% of the window width.

But there are only sm and lg sizes allowed with NgbModal.

How can I increase the width of the modal or probably use a custom class to increase modal width?

I tried setting values like xl to size but it does not work. I also tried customizing the CSS of the modal class but this did not work either.

like image 395
Anuj TBE Avatar asked Sep 19 '18 21:09

Anuj TBE


People also ask

How do I customize my modal size?

Modal Size 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.

How do you increase modal size in Reactstrap?

The docs reactstrap really bad to explained. Don't forget everyone, you can also do size="xl" . To achieve greater sizes than this, you have to use a stylesheet imported and on the Modal component itself, specifically a property called contentClassName . By writing to a separate file like styles.

How do you use Ngbmodal?

As of today the open method of https://ng-bootstrap.github.io/#/components/modal has the following signature: open(content: string | TemplateRef<any>, options: NgbModalOptions) . As you can see from this signature you can open a modal providing content as: string.


1 Answers

You can set the 'windowClass' property referencing some class, so your code would be like:

openViewDescriptionModal(id) {
  const viewModal = this.modalService.open(ProductComponent, {size: 'lg', windowClass: 'modal-xl'});
}

and then, on some .css you're using, add your own class with the custom size to override like:

.modal-xl .modal-lg {
  max-width: 90%;
}
like image 191
Andre Knob Avatar answered Nov 15 '22 22:11

Andre Knob