1

I have the like following in my markup:

<div *ngFor="let item of someArray; let i = index">
    <p [routerLink]="['profiles', profiles[i], 'posts', posts[i], 'likes', likes[i]]"</p>
</div>

In my Angular Component I have the following arrays:

profiles: any = []
posts: any = []
likes: any = []

Sometimes my "profiles" array might have elements and not my other arrays. If this happens then the routing will be broken. I have tried adding "?" to mark is as optional:

<p [routerLink]="['profiles', profiles[i]?, 'posts', posts[i]?, 'likes', likes[i]?]"</p>

This doesn't exactly work.

charlitos
  • 105
  • 2
  • 10

1 Answers1

3

Angular supports three different kinds of routing parameters:

  • Required
  • Optional
  • Query

The syntax for each type is slightly different and you have to use the correct syntax for each of the types to work correctly.

See this post for more information: Sending data with route.navigate in Angular 2

DeborahK
  • 57,520
  • 12
  • 104
  • 129