Angular 2 components: communication from child to child

I have three components in an Angular 2 application: C0, C1, and C2. The first (C0) is an html template that has several child components (ui elements). Now, if someone presses a button in C1 (menu), how can I notify C2 (calendar) about this?

enter image description here

I tried a few examples on the component link page from the Angular site. I ended up with an approach where I took an EventEmitter in C1 to notify the parent of C0. And then used the installer to notify C2 .

It works, but it seems very dirty, even for a hand full of events. This cannot be a solution if there can be hundreds of events at the end in my application.

?

+4
4

, EventEmitter C1, .
C2 C0, C2 , :

<c1 (customEvent)="c2.onClick($event)"></c1>
<c2 #c2></c2>
+7

, , Observable, Observable - , - . fooobar.com/questions/1010729/..., , .

+3

?

, ;).

, , , , , .

, . , , .

+1

?

, , , , ( angular2, ngrx/store). , , , .

Google and watch a few videos, this is a very interesting way of working, and you will also begin to understand the role of rxjs and how it can help in your application.

0
source

Source: https://habr.com/ru/post/1657989/


All Articles