css 带值和管道的动态类名

zynd9foi  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(93)

我使用天气图标动态与天气API。我想图标动态变化,因为我不想有5个以上的选项开关。我在动态创建scss类时遇到了问题。

<i [class]="'wi wi-day-' + '{{weather.daily.weathercode[0] | lowercase}}'"></i>
<i class="wi wi-day-thunderstorm" ></i>
"'wi wi-day-' + '{{weather.daily.weathercode[0] | lowercase}}'"

第2行显示一个雷暴图标,第3行打印“'wi-wi-day-' + 'thunderstorm'”。我不明白为什么1行不行。

nafvub8i

nafvub8i1#

不要混合使用[]{{}}符号:
或者用途:

<i class="wi wi-day-{{weather.daily.weathercode[0] | lowercase}}"></i>

<i [class]="'wi wi-day-' + (weather.daily.weathercode[0] | lowercase)"></i>

相关问题