Share data between components using a service in Angular2

前端 未结 3 912
醉酒成梦
醉酒成梦 2020-12-03 03:21

I am developing an application using angular2. I have a scenario where I need to pass complex data (array of objects) from one component to another component(they are not pa

3条回答
  •  鱼传尺愫
    2020-12-03 04:02

    You could achieve through sharing data between two components using Observables.

    I didn't write this post but its quite useful and easy to understand -

    A quick post to show an example of something that got me stuck for a little while - how to communicate between components in Angular 2/4.

    The solution is to use an Observable and a Subject (which is a type of observable)

    http://jasonwatmore.com/post/2016/12/01/angular-2-communicating-between-components-with-observable-subject

提交回复
热议问题