【问题标题】:How to open modal that is in child component from parent?如何从父级打开子组件中的模态?
【发布时间】:2018-04-11 17:04:20
【问题描述】:

我有点击按钮的布局表单。在其他组件中,我有内部有模式的布局,所以当我点击布局时,我想打开模式。

https://plnkr.co/edit/wJjPL9ZYYsOapw8ylD12?p=preview

这是我的笨蛋。有什么建议我该怎么做?我收到子未定义的错误。

  <layout>
     <div class="body">
      <common-modal  #childModal [title]="'common modal'"> 
    <div class="modal-body">
    {{5+7}} {{item}}
    Hi heloo </div>
    </common-modal> 
     </div>
    </layout>

【问题讨论】:

    标签: angular


    【解决方案1】:

    &lt;layout&gt;设置模板变量的属性:

    <layout [child]="childModal">
    ...
    

    在布局组件中:

       @Input() child;
    ...
      show(){
       this.child.show();
      }
    

    DEMO

    【讨论】:

    • tnx ......这很容易......对你来说:P
    猜你喜欢
    • 2018-05-18
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    相关资源
    最近更新 更多