I am working in Angular 7 . where I am passing object to another component , I am doing it using @input decorative , but components are siblings , so How I can pass the object to another component
Asked
Active
Viewed 4,764 times
0
-
Possible duplicate https://stackoverflow.com/questions/41954484/communicate-between-two-child-components-in-angular-2 .Version may change but the technique is same. – Sreemat Feb 11 '19 at 06:25
2 Answers
1
It is better use Service for the communication in this scenario.
In service u can use Subject which can act as both observer and observable.
ex.
In Service
someSubject = new Subject<any>();
In component one
someService.someSubject.next(objectUWantToSend);
In Component two u can subscribe or vise versa
someService.someSubject.subscribe((receiveObjectHere) => {});

anees
- 334
- 1
- 6
0
@input decorative can only be used for passing values from parent to child components.
For communication between siblings or any components use rxjs subject and Observable instead.
You can follow this - http://jasonwatmore.com/post/2018/06/25/angular-6-communicating-between-components-with-observable-subject

toothful
- 882
- 3
- 15
- 25