last day (15 days later) » 

11:09 AM
0
A: Sending whole object from one component to another in angular 2

Farouk El kholyAs an answer for the question in the title, i would said create a service to pass data between components. Since its a router implementation you can pass the repertoire as a route parameter. Follow these steps: 1)Modify the route in app.routes.ts to take a param { path: 'reserve/:repertoire',...

 
Thank you for answering this. I use Technique 2 but now I am not redirected to /reserve component
 
Can you give me more info, you had an error or something ?
 
My URL now looks like localhost:4200/reserve;repertoire=%5Bobject%20Object%5D There was no error in browser console. Basically I want to click on the Reserve link and call function
 
Can you try this please: this.router.navigate(['/reserve', JSON.stringify(repertoire)]); }
Edited: this.router.navigate(['/reserve',JSON.stringify(repertoire)]‌​);
 
I am redirected now :) I have simple page reserve-form.component.html like this <div> <h3><label>{{repertoire.id}}</label></h3> </div> and I am not getting id printed
Ok
 
11:11 AM
I think you need to JSON.parse(repertoire) in order to access the attributes and i suggest to use {{repertoire?.id}} "?" which means render this when the attribute is availabe
 
JSON.parse requires string so I am getting an error now
Also tried {{repertoire?.id}} but no result
 
lets agree for the next messages on sending error messages :) Before my JSON.parse comment you tried to log repertoire ? and can you try to console.log("typeof repertoire",typeof repertoire)
 
console log gives me
typeof repertoire string
 
constructor(private activatedRoute: ActivatedRoute) {
this.subscription = activatedRoute.params.subscribe(
(param: any) => this.repertoire = JSON.parse(param['repertoire'])
);

console log("this.repertoire :",this.repertoire);
console log("typeof this.repertoire :",typeof this.repertoire);
}
 
11:26 AM
I used
(param: UpcomingRepertoire) => this.repertoire = JSON.parse(param['repertoire'])

and I am getting id printed now :)
 
haha finally :) i am happy for you go on (Y)
 
Thank you very much. It really helped me :)
 

last day (15 days later) »