angularrouterlink

Angular button routerLink syntax explanation


i need explanation for the syntax below:

<button [routerlink]='[./plans]'>press here

where can I find documentation about this syntax? why the brackets around the URL? and the bracket around routerlink is just like (dynamic) property/data binding?

I am not sure where to find documentation about this.


Solution

  • Well, you need the brackets because you want that the right side of your assignments to be evaluated. If you would omit the brackets, it would just be a string with brackets inside of it.

    The array notation gives you the possibility to mix in variables. So for example, you could add an id property from your component, and during runtime, the value would be used. Angular concatenates that array together to a valid string.

    In your case, you don't use any properties. It is just a static value. So you could also just write <button routerLink="./plans">.

    Here's the documentation: https://angular.io/api/router/RouterLink