None
None

Reputation: 9247

Set query params if exists?

I have this link:

<a [routerLink]="[menu.url ||'/']" [queryParams]="{procesId: menu.refParameter3}">

What i want is to check if this menu.refParamter3 exists if exists then add it in queryParams, if not leave empty. Any suggestion?

Upvotes: 1

Views: 823

Answers (2)

brijmcq
brijmcq

Reputation: 3418

What I would do is put an *ngIf inside the tag that checks if menu.refParameter3 exists then display the necessary template

Something like this

   <!-- if refParameter3 exists -->   
    <a  *ngIf="menu.refParameter3" [routerLink]="[menu.url ||'/']" [queryParams]="{procesId: menu.refParameter3}">
   <!-- if there is no refParameter3 -->
     <a  *ngIf="!menu.refParameter3" [routerLink]="[menu.url ||'/']">

Upvotes: 1

JohnB
JohnB

Reputation: 40

You should set your variable in the controller.

For example:

$scope.procesId;
if ($scope.menu.refParameter3) {
    $scope.procesId = $scope.menu.refParameter3;
}

And when you pass this variable it will be either empty or containing the refParameter3 value.

Upvotes: 0

Related Questions