gpt4 book ai didi

javascript - 带有 !important 的 pre 标签中的 ng-style 不起作用

转载 作者:行者123 更新时间:2023-11-28 06:03:32 26 4
gpt4 key购买 nike

<pre ng-style="(errmessage) ? { 'width':'100%', color:'red !important' } : { 'width': '0%' }">{{errmessage}}</em></pre>

如果错误消息不为空,我想使用 ng-style 将来自指令 {{errmessage}} 的预标记错误消息的颜色覆盖为红色。

最佳答案

最好使用 ng-class 而不是 ng-style

在css中添加两个类:

.has-error {
width:100%;
color: red !important;
}
.no-error {
width:0%;
}

并在html中使用它

<pre ng-class="errmessage ? 'has-error': 'no-error'">{{errmessage}}</pre>

关于javascript - 带有 !important 的 pre 标签中的 ng-style 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36607191/

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