Passing objects in routing [duplicate]

六眼飞鱼酱① 提交于 2019-11-29 06:44:46

You can create a SessionService class and pass it around your App via Dependency Injection.

Once the user is selected you can attach the relative data to the SessionService instance injected via DI and retrieve it in the userDetails Component.

I hope it helps

Günter Zöchbauer

Passing objects by routing is quite limited. Using a service is the better option. If you provide a service instance by the parent component, then the same instance gets injected in parent and child and you have the shared data available immediately.

See also https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service

In RC.4 also data for routes was re-introduced How do I pass data in Angular 2 components while using Routing?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!