1
votes

I'm working on an Angular4 project. Everything works great till now, but I'm finding myself hard coding the path of routerlink directly into the html templates:

<a routerLink="/example" >link</a>

I want to avoid it somehow and bind it to the routing module I have.

Is it possible (and logical)? What is the best practice regarding paths?

Thanks

1

1 Answers

1
votes

For binding you need [] or {{}} (never both together) like

[routerLink]="fieldWithPath"

or

routerLink="{{fieldWithPath}}"
export class MyComponent {
  fieldWithPath:string = '/example';
}