【发布时间】:2017-04-14 23:00:05
【问题描述】:
我遇到了一个问题,之前已经提到过,但是像这样的解决方案: What is the proper use of an EventEmitter?
为了方便起见,我想在共享链接上举这个例子:
让我们开始吧: 首先,我在 app.module.ts 中有这些路由:
{path: 'dash/:project_id', component: DashProject, children: [
{path: '', component: null},
{path: 'task/form', component: TaskForm},
{path: 'task/:task_id', component: TaskView}
如您所见,DashProject 是我的父母,其他人是孩子。我还在 DashProject 的模板中包含了所需的
<router-outlet></router-outlet>
部分包含子项。
但在这个提到的例子中,我需要包含
<child (notifyParent)="getNotification($event)"></child>
现在我在我的父模板中做了这样的:
<child (notifyParent)="getNotification($event)"></child>
<router-outlet></router-outlet>
问题:当我将<child (notifyParent)="getNotification($event)"></child> 添加到我的父模板时,子组件已经包含在父模板中,即使它没有被 URL 路由调用。 当我删除该部分时,父组件之间的交互-child 不再工作了。
如果我将它们添加到子模板中,我会得到一个永无止境的循环并崩溃。
任何人都可以看到我的问题或知道导致此错误的原因吗?我在网上看到了一些例子,就像上面分享的一样,都在使用类似的解决方案,但它对我不起作用。
提前致谢!
亲切的问候,亚德博
【问题讨论】:
标签: javascript angular typescript angular2-routing