0

I am trying to create links with a list of urls dynamically:

<span *ngIf="item.type=='link'">
          <a  class="nav-link" [routerLink]="item.routerLink" skipLocationChange>{{item.label}}</a>
        </span>

this solution is working fine when I am running dev in my localhost, but I get the following error when trying to build my library:

RROR: Can't bind to 'routerLink' since it isn't a known property of 'a'. ("<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
  <a class="navbar-brand" [ERROR ->][routerLink]="navBar.routerLink" skipLocationChange><img src="{{navBar.imagePath}}" height="40px" wid")
Can't bind to 'routerLink' since it isn't a known property of 'a'. ("item':'nav-item dropdown'">
        <span *ngIf="item.type=='link'">
          <a  class="nav-link" [ERROR ->][routerLink]="item.routerLink" skipLocationChange>{{item.label}}</a>
        </span>

this is the list of my dependencies:

"@angular/animations": "~8.2.9",
    "@angular/common": "~8.2.9",
    "@angular/compiler": "~8.2.9",
    "@angular/core": "~8.2.9",
    "@angular/forms": "~8.2.9",
    "@angular/platform-browser": "~8.2.9",
    "@angular/platform-browser-dynamic": "~8.2.9",
    "@angular/router": "~8.2.9",
1
  • item.routerLink this value are you getting from any API ? and is there any chance of having empty value ? Commented Feb 24, 2021 at 6:05

1 Answer 1

1

Have you imported import {RouterModule} from '@angular/router';? RouterModule this should work. Or another way to make dynamic routes is you can call function and inside your component.ts file you can manage it. Example

import { Router } from '@angular/router';

export class ExampleComponent {

    constructor(private router: Router,) {}

    routerLinkTo() {
        this.router.navigate(["/foo"]);
    }
}

Please check this example here

For more Router function please check Angular Documentation here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.