【发布时间】:2018-02-26 13:41:20
【问题描述】:
我正在通过 ModalController 显示组件 EventFeedbackComponent。现在我想订阅EventFeedbackComponent 中的Subject。如何访问组件实例以实现我的目标。
我当前的代码:
let modal = this.modalCtrl.create(EventFeedbackComponent);
modal.present();
// This is not working. Throws the error "ERROR TypeError: Cannot read property 'subscribe' of undefined"
modal._component.feedbackSubmit.subscribe(feedbackResponse => {
console.log(feedbackResponse);
});
文档在这方面没有帮助:https://ionicframework.com/docs/api/components/modal/ModalController/
我的用例:
- 我的
Service中有一个事件列表,我需要获得反馈。 -
EventFeedbackComponent具有获取单个事件反馈的控件。 - 现在,我展示 EventFeedbackComponent 以获取第一个事件的反馈并通过
Subject监听事件feedbackSubmit - 在提交
feedback时,我会显示 Success Toast 并在 Service 中切换我的服务变量以显示下一个事件。 - 重复上述点,直到我获得所有未审核事件的反馈,这些事件具有通过模型显示的相同组件。
【问题讨论】:
-
你能在这里告诉我你的用例吗?
-
您的设计似乎适得其反。我建议您在服务中使用主题而不是组件
-
更新了我的用例。猜猜它现在应该更有意义了。
标签: angular typescript ionic-framework ionic3