Hi I have a template driven form like Url : https://angular-template-driven-feedbackform.stackblitz.io/ and need to pass data from this form component to another component like usercomponent even this form data coming in console please give me appropriate solution with reason..Thanks
Asked
Active
Viewed 285 times
1 Answers
0
Best way to share data between components is using a service according to your scenario you can pass values to the service when the user clicks on signup and use those data in another component by subscribing to that service. Your can use Behavior-subject or subject to find more information please follow the link on angular guide. https://angular.io/guide/component-interaction#parent-and-children-communicate-via-a-service
To know what is Behavior-subject and subject please follow What is the difference between Subject and BehaviorSubject?
hope this helps!

umesh99
- 215
- 1
- 11
-
Yes it is ok but i need something that is working example if you provide me on stackblitz ...thanks – Ganny Dec 27 '18 at 09:10
-
ok follow this if you use behavior-subject https://stackblitz.com/edit/best-example-of-passing-data-through-an-object-using-a-service or if you use subject https://stackblitz.com/edit/angular2-communicating-between-components – umesh99 Dec 27 '18 at 09:19
-
Hi Umesh I implement all in my code but after submit how to route to another page where I have to show message after function call I stuck there can you please give me any solution? – Ganny Dec 27 '18 at 11:53
-
Use navigate or navigatebyurl methods like this gotoHeroes() { this.router.navigate(['/heroes']); } – umesh99 Dec 27 '18 at 12:45
-
I set up routing and redirect to a feedback component but from home to component message did not display I have added here https://angular2-communicating-between-components-u2mkue.stackblitz.io/ can you pls see... – Ganny Dec 27 '18 at 14:08
-
1Ok you have to use behavior-subject now its working fine plez follow this https://stackblitz.com/edit/angular2-communicating-between-components-vp8m84?file=app%2Fhome%2Fhome.component.ts – umesh99 Dec 27 '18 at 15:54