Build Dynamic Angular Navigation with ngFor

Share this video with your friends

Send Tweet

It’s often easier to build out your navigation dynamically so that you have programmatic control of which navigation elements appear (and those which don’t). You can leverage the power of Angular’s *ngFor directive to build out navigation based on any set of data you provide with urls.

Kevin Pinny
Kevin Pinny
~ 7 years ago

After all I thing we don't need [routerLink]. It is working like blove. We don't need "[ ]" at all.

<a *ngFor="let nav of navs" routerLink="{{nav.url}}" routerLinkActive="active" [routerLinkActiveOptions]="{exact:true}">{{ nav.content }}</a>

From what I understand [attribute]="value" === attribute="{{}}", I prefer reading the first one though. Less noise.