ngStyle不适用于angular2中的!important [英] ngStyle does not work with !important in angular2
问题描述
如果我写的话,在angular2模板中
In angular2 template if I write:
[ngStyle]="{'background-color': 'red'}"
它按预期工作.但是如果我写:
it works as expected. But If I write:
[ngStyle]="{'background-color': 'red !important'}"
它不起作用(也没有显示任何错误)
it's not working (not showing any error also)
推荐答案
由于angular2文档仍然不够完善,我认为将解决方案作为答案可能会有所帮助(也许对某人有帮助).
As angular2 documentation is still not good enough, I think it may be helpful to post the solution as an answer (may be it helps someone).
根据angularjs(1.x)git存储库问题
According to angularjs (1.x) git repository issue
您无法使用DOM风格的!important指令Chrome和FF(可能还有其他)中添加属性
You're not able to use the !important directive in the DOM style property in either Chrome nor FF (probably others too)
因此,我没有使用[ngStyle]中的!important来使其工作:
So instead of using !important in [ngStyle] I use the following way to make it work:
[attr.style]="'background-color:red !important'"
它按预期工作.
这篇关于ngStyle不适用于angular2中的!important的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!