如何使按钮从外部组件触发模式

时间:2019-02-28 09:24:01

标签: javascript components bootstrap-modal blazor

您好,我有一个modal,目前可以通过按钮获取toggled。我想从外部组件切换模式,但是我想将此按钮保留在模板中。

我可以通过外部按钮将点击重定向到该按钮并切换模式吗?

ModalComponent

<div class="container">

     //I want this button to get triggered somehow from outside of component
    <button  class="btn btn-primary" data-target="#campModal" data-toggle="modal"></button>

    <div class="modal fade" id="campModal" tabindex="-1" role="document">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h5 class="modal-title">Create</h5>
                </div>
                <div class="modal-body">
                    <CampaignForm onclose="@this.OnClose" onsubmit="@this.OnSubmitAsync"></CampaignForm>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary">Submit</button>
                    <button class="btn btn-primary" data-dismiss="modal">Close</button>
                </div>

            </div>
        </div>
    </div>
</div>

外部来源

<div>
<button onclick="[trigger the button of the modal]"></button>
<Modal></Modal>
</div>

PS 我需要的是ModalComponent使其button保持为可重用组件,并以某种方式公开一个参数,该参数(从外部组件更改)会触发模态

我基本上需要将点击从外部组件重定向到ModalComponent内部的按钮。(模式按钮将被隐藏)

0 个答案:

没有答案