Pass Data Between 2 Components In Angular
I'm trying to pass data from my ag-Grid to a form in a new component by clicking on the row. I could get the data from the row by clicking on the cell via onCellClicked . But i don
Solution 1:
Why not use the service class to fetch the data based on the id or index of data, so example you pass id as a param to new child component and run a ngOninit to fetch that data based on identifier
ngOnInit() {
this.sub=this._Activatedroute.paramMap.subscribe(params => {
const id = params.get('id');
let dealer=this.dealsService.getDealer(id);
});
I am creating getDealer() based on assumption you have a get single dealer return function in your service if not then just run dealer.find(dealer => dealer.ID==id);
And then on your method in parent route =>
makeCellClicked(event) {
this.router.navigate(['/dealer-details', event.id]);
}
Not sure if this answers your question on how to fetch and display that data row.
Solution 2:
The shared service was the right solution. How to pass data between two components in Angular 2
Post a Comment for "Pass Data Between 2 Components In Angular"