Child to Parent Component Communication in Angular 2

2.5k views Asked by At

I'm using https://github.com/mgechev/angular-seed for my project. I need to update value in shopping cart via header component while clicking addtocart in my item component. Please help me. I'm new to Angular 2. I used the same code structure as in https://github.com/mgechev/angular-seed.

2

There are 2 answers

0
coderdark On

You can use angular services to communicate between components, directives and services. You can also use @Input and @Output to communicate between parent child components. There is other ways, depending on your needs...Check the angular page:

https://angular.io/docs/ts/latest/cookbook/component-communication.html

0
aryan On

Define the property in services with type of subject (observable) and invoked or used that property in child component, use the next function and pass the data in next function. In parent component just subscribe this observable. following https://github.com/aryanisml/Angular-Services-Observables will help you.