我在 html 文件中使用此变量作为颜色时遇到错误
<span style=`color: ${_currentConfig.statusColor};`>{{ _currentConfig?.content }}</span>
这里出了什么问题?
main.js:1 DOMException: Failed to execute 'setAttribute' on 'Element': '${_currentConfig.statusColor};
' 不是有效的属性名称。`
您可以使用Angular的绑定语法来动态设置样式。这是一个例子:
<span [style.color]="_currentConfig?.statusColor">{{ _currentConfig?.content }}</span>