ngx-bootrap - 隐藏事件未触发
我有一个来自 ngx-bootstrap 的模态,当关闭时我想触发我的角度分量中的一个函数。但无论我如何尝试捕捉事件,我都无法捕捉到。
我想要触发的事件是直接的 - 我现在只想在控制台中看到它:
// Reset the user data
clearUserData() {
console.log('Data Cleared');
}
方法一 - 直接使用模态模板:
<ng-template #template bsModal (onHide)="clearUserData()">
...
</ng-template>
结果:什么也没发生 - 所以控制台日志并且没有错误消息
方法二: 使用模态服务:
// Open Progress Modal
buyNow(template: TemplateRef<any>) {
// Open the model
this.modalRef = this.modalService.show(template);
this.modalRef.content.onClose.subscribe(result => {
console.log('results', result);
});
}
结果:这在控制台中给了我一条错误消息: 类型错误:无法读取 null 的属性(读取“onClose”)
I have a modal from ngx-bootstrap and when closed I want to trigger a function in my angular component. But no matter how I try to catch the event I can't.
Event I want to fire is straight forward - I just want to see it in the console for now:
// Reset the user data
clearUserData() {
console.log('Data Cleared');
}
Approach one - using the modal template directly:
<ng-template #template bsModal (onHide)="clearUserData()">
...
</ng-template>
Result: Nothing happens - so console log and no error message
Approach two: Using the modal service:
// Open Progress Modal
buyNow(template: TemplateRef<any>) {
// Open the model
this.modalRef = this.modalService.show(template);
this.modalRef.content.onClose.subscribe(result => {
console.log('results', result);
});
}
Result: This give me an error message in the console:
TypeError: Cannot read properties of null (reading 'onClose')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到过这个 stackoverflow 答案。接受的答案和巴坦多的答案也是如此。因此,我们的想法是使用
modalService
并且他们放置了一个dismiss Reason
属性,然后您可以在其中调用clearUserData()
这就是
我分享参考链接的方式。 SO的链接
I have come across this stackoverflow answer. The accepted answer and Bartando's answer as well. So the idea is to use the
modalService
and there is adismiss reason
property that they have put and then inside you can call yourclearUserData()
That's how this goes
I am sharing the reference link as well. SO's LINK