简体   繁体   English

Angular 4 ng-bootstrap关闭来自子组件的Modal

[英]Angular 4 ng-bootstrap close Modal from child component

I am using ng-bootstrap' modal and got stuck with a problem. 我正在使用ng-bootstrap'模态并遇到问题。
Situation:- I have a form component that I am showing in a modal. 情况: - 我有一个表单组件,我在一个模态中显示。 Now, I want to close the modal once the user submits the form and backend confirms the success. 现在,我想在用户提交表单后关闭模式,后端确认成功。
problem:- As guided here , I don't have a reference of the modal in child component to close it. 问题: - 按照这里的指导,我没有引用子组件中的模态来关闭它。 please suggest a way. 请提出一个方法。 Thanks. 谢谢。

You could pass the modal reference to it using a child input property. 您可以使用子输入属性将模态引用传递给它。

<child-component [parentRef]="ref">

And then in your child component you'll have to define something like: 然后在您的子组件中,您将必须定义以下内容:

@Input() ref;

Please take a look at the Angular documentation here. 请在这里查看Angular文档

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

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