Reputation: 643
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
Upvotes: 0
Views: 4890
Reputation: 344
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) => {});
Upvotes: 1
Reputation: 892
@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
Upvotes: 0