I have no idea how to make it good. I want to send JSON between 2 Angular Components. I thinking about routing but how to send something like POST between this, to components i know how to use @inputs/@Outputs , but i have to change Url and reload content. The problem is it is not only id but list of check ides.
Component
selectedAll = [];// it is array od Id [1,2,3,4...];
goToDetail(): void {
this.selectedIDService.saveIds(this.selectedLight);
console.log( "Show: "+this.selectedIDService.retrieveIDs().length); <-- give me good number
this.router.navigate(['/detailSearch']);
}
HTML button nothong intresting
<button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown" (click)="gotoDetail()">
Of course i want to get this on my detailSearch component.
import { Injectable } from '@angular/core';
@Injectable()
export class SelectedIdService {
public myIds: Array<Number>=[];
constructor() { }
saveIds(produIds:any){
this.myIds = produIds;
console.log(this.myIds);
}
retrieveIDs():any[]{
return this.myIds;
}
}
--------Other component-------
providers : [SelectedIdService]
constructor( private route: ActivatedRoute,
private selectedIdService :SelectedIdService) { }
ngOnInit() {
var selected:any[] =this.selectedIdService.retrieveIDs();<<-- empty
}
do u know why?