Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Condition in queryParams angular2

<a href="#"
                        [routerLink]="[isTrue?'/location-1':'/location-2', '']"
                        [queryParams]="{id:loc.id,l:'loc'}">

Here when value of isTrue is true
/location-1/?id=1&l=loc

But when value of isTrue is false, I need
/location-2/?id=1&l=loc2&idL=2

So how do I modify parameter conditionally?

like image 558
vusan Avatar asked Oct 30 '25 01:10

vusan


1 Answers

Found solution, we can also add ternary condition before object on queryParams.

[queryParams]="isTrue?{id:loc.id,l:'loc'}:{id:loc.id,l:'loc2',idL:loc.lId}"
like image 141
vusan Avatar answered Oct 31 '25 15:10

vusan