A
A
AskJs2018-06-14 11:52:50
css
AskJs, 2018-06-14 11:52:50

How to open bootstrap modal from parent component?

There is a Bootstrap modal window (in an Angular 2+ project):

<div bsModal #largeModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>

opens modal: A modal component that is inserted into the parent. The question is how to open the modal (largeModal.show()) from the parent component? * PS typescript does not know what largeModal.show() is;
(click)="largeModal.show()"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Eremin, 2018-06-14
@EreminD

I do it like this:

<button type="button" class="btn btn-sm btn-outline-success" (click)="openVerticallyCentered(content)">Create new</button>
<ng-template let-c="close" let-d="dismiss" #content>
  <app-create-single-form [book]="activeBook" [user]="activeUser" [c]="c" [d]="d"></app-create-single-form>
</ng-template>

openVerticallyCentered(content): void {
    this.modalService.open(content, {centered: true, size: 'lg'});
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question