ng样式在与的预标记中!重要的是不能工作

ng-style in pre tag with !important not working

本文关键字:重要的 工作 不能 样式 ng      更新时间:2024-06-18

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

如果errormessage不为空,我想使用ng样式将来自指令{{errmessage}}的标记前errormessage的颜色覆盖为红色。

最好使用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>