gpt4 book ai didi

angular - ngStyle 颜色为真假?

转载 作者:行者123 更新时间:2023-12-03 23:30:53 24 4
gpt4 key购买 nike

<p [ngStyle]="{'color' : 'value == white', '!value == red' }">Hello</p>

关于如何使用具有真假值的 NgStyle 的任何想法?

最佳答案

[ngStyle]指令等待一个表达式。

你可以这样做:

<p [ngStyle]="{ 'color': value }">Hello</p>
<!-- When the value is === 'red' the color red will be applied to <p> and so on... -->

或者...
<p [ngStyle]="{ 'color': (value ? 'white' : 'red') }">Hello</p>

并操纵这个 value某处变量。

关于angular - ngStyle 颜色为真假?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42405132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com