angular - Angular 6中的孩子与父母的沟通
问题描述
我的 Angular 组件中有标题和正文。
在标题中有一个通知计数,并且希望在正文中的用户更改计数时更新计数。
app.routing.ts
export const AppRountes: Routes = [{
component: LayoutComponent,
children: [
{
path: 'notification',
loadChildrent: './notification/notification.module#NotificationModule'
}
]
}]
我有一个 NotificationComponent 用于通知。
通知图标和计数在 LayoutComponent 中。
在这里,我想从 NotificationComponent 通知到 LayoutComponent。
我可以使用 @ViewChild 从 LayoutComponent 与 NotificationComponent 进行通信,但不确定如何从子项与父项进行通信。
解决方案
通常,您会使用EventEmitter
plus @Output
,因为您使用的是路由器,所以您不能真正做到这一点。我想你可以在这里找到答案:Angular 2 output from router-outlet
推荐阅读
- android - 如何合并两个bundleOf?
- google-tag-manager - 如何使用 Google Tag Manager 在 Safari 上跟踪网络事件
- react-native - 世博会每周通知在 Android 上
- arrays - 初学者问题:Func 返回字符串和数组
- bash - Bash 使用 3 位前缀和分隔符批量重命名文件夹
- java - 如何在 Java libGDX 中为我的游戏正确添加足迹
- nutch - Apache Nutch 1.17 索引器兔子不工作
- c++ - 断点的工作方式与示例中的不同
- r - `r`/`rlang`/`dplyr`:如何使 `sym` 对 `NULL` 有弹性?
- python - 我如何在 model.add(Flatten()) 层之后访问数据?