简体   繁体   English

角度2:模式开放事件

[英]Angular 2: Modal open event

in my Angular 2 application, I am using modal component : 在我的Angular 2应用程序中,我正在使用模式组件

<div bsModal #addRecordModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true">
<div class="modal-dialog ">
  <div class="modal-header">
  </div>
  <div class="modal-body" style="min-height: 270px;">
      <app-my-test [modal]="addRecordModal"></app-edit-record>
  </div>
  ...

In the modal-body, there is the MyTestComponent , which contains ModalDirective: 在模态主体中,有MyTestComponent ,其中包含ModalDirective:

@Component({...})
export class MyTestComponent implements OnInit, OnDestroy {
    @Input() modal: ModalDirective;
    ...

I wonder if it is possible somehow to detect modal open event inside the MyTestComponent? 我想知道是否有可能以某种方式检测 MyTestComponent内部的模式打开事件吗?

You can declare $ as any and then you will have access to all these events mentioned here https://www.w3schools.com/bootstrap/bootstrap_ref_js_modal.asp In shown.bs.modal function, you can set this.modalShown as true which will be passed to your child component using @Input. 你可以声明$任何然后你将有机会在这里所提到的所有这些事件https://www.w3schools.com/bootstrap/bootstrap_ref_js_modal.asp在shown.bs.modal功能,可以设置this.modalShown为真的,将使用@Input传递给您的子组件。 You can listen for changes to this input in child component using ngonchanges.Hope this helps you. 您可以使用ngonchanges侦听子组件中对此输入的更改。希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM