我正在使用组件作为模板打开一个模式,一切正常,模式打开,我正在订阅 onHide 事件,订阅也有效。
但我在这里面临一个挑战
我想发送一个特定的原因,例如:“消息添加成功”作为原因。我怎样才能做到这一点?
如何发送特定字符串作为原因?
目前,我尝试在 Message AddComponent 组件中设置一个值,并使用 bsModalRef.Content 在父组件中访问它,但这不是一个好主意。
newMessage() {
this.bsModalRef = this.modalService.show(MessageAddComponent, {
class: 'modal-lg'
});
this.subscriptions.push(this.modalService.onHide.subscribe((reason: string) => {
// i dont like this approach
if (this.bsModalRef.content.anySuccessfulAction) {
console.log('foo and bar')
}
this.unsubscribe();
}));
}
为了简化您的订阅,您可以通过以下方式创建“一次性”订阅.take() or first()操作员:
this.modalService.onHide
.pipe(take(1))
.subscribe(() => {
console.log(this.bsModalRef.content)
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)