0

If url contains ?edit= "true" orfalse, I need to append that value to my router link.

Based on the below feedback I've modified my code.

But i'm this error ?edit=%5Bobject%20Object%5D . value of the edit is not getting appended to the URL.

Please tell me what i'm doing wrong here.

urlValue: any;
ngOnInit() {
  this.urlValue = {
    edit: this.activatedRoute.queryParamMap.map((params) => params.get('edit'))
  };
}
<li>
  <a class="production_model_col" [routerLink]="['/flow/PFSession']" [queryParams]="urlValue"><span >View Production Plan</span></a>
</li>
arunkumar
  • 333
  • 1
  • 9
  • 25
  • Possible duplicate of [How to pass query parameters with a routerLink in the new Router V 3 alpha (vladivostok)](https://stackoverflow.com/questions/37880876/how-to-pass-query-parameters-with-a-routerlink-in-the-new-router-v-3-alpha-vlad) – Jota.Toledo Dec 01 '17 at 08:25
  • Why are you accessing to the url through the window property? Do it the angular way... – Jota.Toledo Dec 01 '17 at 08:27
  • I've updated my code. But i'm getting error `?edit=%5Bobject%20Object%5D` – arunkumar Dec 01 '17 at 10:10

1 Answers1

0

Use queryParamMap from Activated route as per query parameters documentation as below :

import { Router, ActivatedRoute, ParamMap } from '@angular/router';

constructor(
  private route: ActivatedRoute,
  private router: Router
) {}

ngOnInit() {
  const value = this.route.queryParamMap.map(params => params.get('edit') || false ) ;
  this.urlValue = {
    edit: value
  };
}

and use it as below

<a [routerLink]="['/user/bob']" [queryParams]="urlValue">View Production Plan </a>
ranakrunal9
  • 13,320
  • 3
  • 42
  • 43