我试图从组件中打开一个模式,并调用show方法来响应另一个订阅,如果在订阅之外调用它,它就会正常工作。但是,从订阅中,传递给内容的数据没有在下面刷新,这是代码的一个示例。
//Subscription
$subject.subscribe(res => {
const bs_modal = this._bsModalService.show(ComponentA);
bs_modal.content.data = res;
this._bsModalService.onHide.subscribe(() => {
console.log(bs_modal.content.res_data));
})
})
// Modal Component
@Component({
selector: 'app-modal',
template: `
<div>{{data | json}}<div>
<button (click)="hideModal()">Hide Me</button>
`,
})
class ComponentA {
data: any;
res_data: any;
constructor(_bsModalRef: BsModalRef) {}
hideModal() {
this.res_data = 'Testing';
this._bsModalRef.hide();
}
}在模态打开时,data是空的,每当我关闭模态时,res_data也是未定义的
发布于 2019-07-12 15:13:06
我已经在stackblitz中重新创建了您的代码,在调整了一些东西之后,我能够将数据传递到模型中:https://stackblitz.com/edit/angular-37iw9w。
确保以下几点:
根据您给出的代码示例,这是在假定它们属于一个模块的情况下进行的。
https://stackoverflow.com/questions/57009428
复制相似问题