Angular2 - Share data between components using services

前端 未结 3 1822
灰色年华
灰色年华 2020-11-29 06:20

I have an object that I want to share between my components into an Angular2 app.

Here is the source of the first component:

/* app.component.ts */

         


        
3条回答
  •  心在旅途
    2020-11-29 07:15

    Don't add ConfigService to providers of your component. This results in new instances for every component. Add it to providers of a common parent component. If you add it to your root component or bootstrap(App, [ConfigService]) your entire application shares a single instance.

提交回复
热议问题