繁体   English   中英

Angular 6中的儿童与父母的交流

[英]Child to parent communication in Angular 6

我在Angular组件中有标头和正文。

标头中有一个通知计数,每当用户在正文中更改计数时,便希望更新该计数。

应用程序路由

export const AppRountes: Routes = [{
   component: LayoutComponent,
   children: [
    {
     path: 'notification',
     loadChildrent: './notification/notification.module#NotificationModule'
    }
   ]
  }]

我有一个NotificationComponent用于通知。

通知图标和计数位于LayoutComponent中。

在这里,我想从NotificationComponent通知给LayoutComponent。

我能够使用@ViewChild从LayoutComponent到NotificationComponent进行通信,但是不确定如何从子级到父级进行通信。

通常,您将使用EventEmitter加上@Output ,因为您使用的是路由器,因此您实际上无法做到这一点。 我想您可以在这里找到答案: 路由器出口的Angular 2输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM