[英]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.