Share data between components using a service in Angular2

camaron is right. Your mistake is that you declare UtilityService twice: Once in the providers of SearchComponent. Once in the providers of TransferComponent. You should declare the service ONLY ONCE to make sure both components get the same instance. For this you can choose between either of these options: Declare the service in the providers … Read more

Angular – What is the meanings of module.id in component?

The beta release of Angular (since vesion 2-alpha.51) supports relative assets for components, like templateUrl and styleUrls in the @Component decorator. module.id works when using CommonJS. You don’t need to worry about how it works. Remember: setting moduleId: module.id in the @Component decorator is the key here. If you don’t have that then Angular 2 … Read more

ng2 – dynamically creating a component based on a template

Update2: As @estus mentioned in comments version with className won’t work with minification. To do it working with minification you can 1) add some static key on each of your entryComponents like: export LineChartComponent { static key = “LineChartComponent”; } and then use this key as unique. const factoryClass = <Type<any>>factories.find((x: any) => x.key === … Read more

How to call component method from service? (angular2)

Interaction between components can be indeed achieved using services. You will need to inject the service use for inter-component communication into all the components which will need to use it (all the caller components and the callee method) and make use of the properties of Observables. The shared service can look something like this: import … Read more