Pass an object with queryParams in the Router


I have an array of objects that I reccure with an ngFor. Later down I have a navigation bar in which I redirect to one or another component and I need to pass the selected object above. However, the most I get is to receive a literal "[Object object]


  <div *ngFor="let visit of list">
    <span (click)="selected(">
      <span class="photo">{{ visit.urlFoto }}</span>
      <span id="text-data">
        <span>{{ visit.cliente.nombre }} {{ visit.cliente.apellidos }}</span>
        <span>{{ visit.cliente.apellido2}}</span>
<nav class="navbar navbar-expand-lg">   
  <ul class="nav nav-tabs">
<li class="nav-item">
      <a class="nav-link" [routerLink]="['client']" [queryParams]="{'p': this.index - 1, 'list': this.listVisits[this.index - 1]}">Client Detail</a>

TS of the client component:

ngOnInit() {
    this.sub = this.routeParams.queryParams.subscribe( params => {
      this.index = params['p'];
      this.listVisits = params['list'];
asked by Findelias 04.05.2018 в 11:31

1 answer


You can not, the parameters are collected from the URL, so they are always text. You could use JSON.stringify , but it's really not a good idea.

Ideally, in that case, have a service that communicates to different components or use something like localStorage or sessionStorage to save data (In which case you'll also have to use JSON.stringify

answered by 04.05.2018 / 12:14