각도 라우팅은 대형 개체를 전달하기위한 것이 아닙니다. 경로 매개 변수와 쿼리 매개 변수는 전달할 수 있지만 복합 개체는 전달할 수 없습니다.
구성 요소간에 데이터를 공유해야하는 경우 서비스의 공유 인스턴스를 사용하는 것이 좋습니다.
공유 서비스에 대해 관찰 가능하도록 권장합니다 (단, 어떤 수단으로도 요구 사항은 아님). 예를 들면 다음과 같습니다.
@Injectable()
export class MySharedService {
// BehaviorSubjects start with a default value and replay the latest value to components that subscribe at any point in the lifecycle.
// Subject types do not start with a default value and do not replay the latest value, so if a component subscribes after it's fired, it won't receive the value.
private someStringDataSource = new BehaviorSubject<string>('');
someString$ = this.someStringDataSource.asObservable();
setSomeString(newString: string) {
this.someStringDataSource.next(newString);
}
}
export class AppComponent implements OnInit, OnDestroy {
sub: Subscription;
constructor(private sharedService: MySharedService) { }
ngOnInit() {
// subscribe to data from service
this.sharedService.someString$.subscribe(data => //do something with data);
//send data to service
this.sharedService.setSomeString('newString');
}
ngOnDestroy(){
this.sub.unsubscribe();
}
}
그게 내가 원하는 것입니다. 고맙습니다. – bchampion