尝试在样式中插入打字稿元素时出现术语预期错误

a term expected error when trying to insert typescript element in the styling

在我的 ts 文件中,我有在 html 文件中使用的元素。在此示例中,我使用 element.color(值 = #3b5998)和 element.name(值 = Facebook)。当将值放在图标下方时,一个有效但颜色无效。代码如下所示:

<fa style="color: {{element.color}};" name="{{element.icon}} fa-3x"></fa>

颜色后:有一条红线表示,"a term expected"。但我不知道要改变什么。我知道这是转储错误,但我卡住了。

Image

要绑定到样式,有两种方法:

使用style binding

<fa [style.color]="element.color" [name]="element.icon + 'fa-3x'"></fa>

或使用 NgStyle 指令

<fa [ngStyle]="{ color: element.color }" [name]="element.icon + 'fa-3x'"></fa>

尽量把标签(fa)的属性之间的引号(")去掉,只需要放在所有属性记录的开头和结尾