Home > Back-end >  Angular router link How to pass json into <a ... [queryParams]="q=|JSON|"/>
Angular router link How to pass json into <a ... [queryParams]="q=|JSON|"/>

Time:05-19

From the view of an angular i'd like to fill a query param with a json object.

<ngx-datatable-column name="Sku" prop="product.sku" [flexGrow]="0.5">
  <ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
    <a [routerLink]="['/general','products']" [queryParams]="{q: { search: value } }">
      {{value}}
    </a>
  </ng-template>
</ngx-datatable-column>

Unfortunately, the above code produces the following link: http://localhost:4200/general/products?q=[object Object]

Instead of http://localhost:4200/general/products?q={"search": "SomeSearchValue"}. (html escape ofc.)

How could i make this work?

EDIT:

<a [routerLink]="['/general','products']" [queryParams]="{q: { search: value }.toString() }">

Does not work.

CodePudding user response:

What is it the firts q?

Try this:

<ngx-datatable-column name="Sku" prop="product.sku" [flexGrow]="0.5">
  <ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
    <a [routerLink]="['/general','products']" [queryParams]="{ search: value }">
      {{value}}
    </a>
  </ng-template>
</ngx-datatable-column>

CodePudding user response:

I found the solution, its the json pipe:

    <a [routerLink]="['/general','products']" [queryParams]="{q: { search: value } | json }">
      {{value}}
    </a>
  • Related