为什么在Angular 4中对变量使用撇号 [英] Why use apostrophe for variables in Angular 4
问题描述
我想知道这两行之间的区别.
I want to know about the difference between these two lines.
<p [myHighlight]="'yellow'">Highlighted in yellow</p>
<p myHighlight="orange">Highlighted in orange</p>
myHighlight
是自定义指令,其中所有标签都将设置为自定义颜色.
谢谢.
myHighlight
is custom directive where all tags inside it will be set custom color.
Thanks.
推荐答案
已阅读此页面上有角度的文档,它将告诉您所有有关模板语法的信息.
Have a read of this page on the angular docs it will tell you all about the template syntax.
但是仅将第一行作为表达式求值,而将下面的行作为常量求值.
But simply the top row will be evaluated as an expression and the line below as a constant.
引自文档.
括号告诉Angular评估模板表达式.如果你 省略括号,Angular将字符串视为常量,然后 使用该字符串初始化target属性.它不评估 字符串!
The brackets tell Angular to evaluate the template expression. If you omit the brackets, Angular treats the string as a constant and initializes the target property with that string. It does not evaluate the string!
希望有帮助.
这篇关于为什么在Angular 4中对变量使用撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!