[英]Passing “username” value from one component to another component in Angular 2
[英]Passing object from one component to another component in Angular
我在Angular 7中工作。 在將對象傳遞給另一個組件的地方,我使用@input裝飾,但組件是同級的,所以如何將對象傳遞給另一個組件
@input裝飾只能用於將值從父級組件傳遞到子級組件。
對於兄弟姐妹或任何組件之間的通信,請使用rxjs subject和Observable代替。
在這種情況下,最好將Service用於通信。
在服務中,您可以使用既可以充當觀察者又可以觀察到的Subject。
恩。
服役中
someSubject = new Subject<any>();
在第一部分
someService.someSubject.next(objectUWantToSend);
在第二部分中,您可以訂閱或反之
someService.someSubject.subscribe((receiveObjectHere) => {});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.