英文:
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 <button routerLink="./plans">
.
Here's the documentation: https://angular.io/api/router/RouterLink
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论