Angular按钮routerLink语法解释

huangapple go评论68阅读模式
英文:

Angular button routerLink syntax explanation

问题

我需要解释下面的语法:

<button [routerlink]='[./plans]'>点击这里</button>

我应该在哪里找到关于这种语法的文档?为什么在URL周围有括号?routerlink周围的方括号就像(动态)属性/数据绑定一样吗?

我不确定在哪里找到关于这方面的文档。

英文:

i need explanation for the syntax below:

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

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.

答案1

得分: 0

在你的赋值语句右侧进行评估时,需要使用括号。如果省略括号,它将只是一个包含括号的字符串。

数组表示法允许您混合使用变量。因此,例如,您可以从组件添加一个id属性,在运行时将使用该值。Angular将该数组连接在一起以生成有效的字符串。

在你的情况下,你没有使用任何属性。它只是一个静态值。所以你也可以只写<button routerLink="./plans">

这里是文档链接:https://angular.io/api/router/RouterLink

英文:

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 &lt;button routerLink=&quot;./plans&quot;&gt;.

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

huangapple
  • 本文由 发表于 2023年6月26日 03:57:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76552197.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定