如果内部模态位于角度的另一个组件中,如何关闭?

时间:2020-02-01 07:45:40

标签: html angular

我有一个“客户”组件(父组件),它与“客户页面”组件(子组件)有关。

在父组件中,有一个模态调用子组件。在子组件中,还有两个模型可以工作,就像这三个模型都在同一个组件中一样。

但是当我关闭子组件的模态时,它也会关闭父组件的模态。

我该如何解决?

客户组件HTML(父组件HTML)

<button type="button" class="btn btn-primary btn-sm" id="mymodal" data-toggle="modal" data-target="#myModal">Customer's Page</button>

<div class="container">
    <div class="row">
        <div class="modal fade bd-example-modal-xl" id="myModal" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="staticBackdropLabel">customer info</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <app-customer-page [customer]="currentCustomer"></app-customer-page>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                        <button type="button" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

客户页面HTML(子组件HTML)

<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal-inner" title="Edit"><i class="far fa-edit"></i></button>
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target=".bd-example-modal-sm" title="Delete"><i class="far fa-trash-alt"></i></button>

<div class="container">
    <div class="row">
        <div class="modal fade bd-example-modal-lg" id="myModal-inner" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="staticBackdropLabel">Customer Info</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <app-add-order [order]="currentOrder"></app-add-order>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                        <button type="button" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="container">
    <div class="row">
        <div class="modal fade bd-example-modal-sm" tabindex="-1" data-backdrop="static" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-sm" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="staticBackdropLabel">Attention</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <p>This operation cannot be undone. Are you sure?</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger">Delete</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

客户页面组件HTML

1 个答案:

答案 0 :(得分:0)

data-toggle="modal"

您的模态被绑定到名为modal的相同变量。为数据切换中的每个模式使用不同的名称。