样式属性中的角度表达式在IE中不起作用

jcu*_*bic 10 javascript css jquery internet-explorer-10 angularjs

我有角度1.0.6(我知道它是旧的)我有带表达式的style属性:

<li style="background-color: {{item.color}}">
   <span style="color: {{item.color | contrastColor}}">{{item.label}}</span>
</li>
Run Code Online (Sandbox Code Playgroud)

它工作正常,但不适用于IE(应用程序需要工作> IE10).当我打开Developer工具时,style属性不存在.我试图创建自定义样式指令(因为我认为IE在Angular可以读取它之前删除无效属性)但是使用这个简单的代码,我TypeError: Cannot read property 'replace' of undefined从jquery(在谷歌浏览器上测试)得到了一个错误,因为在我的案例中.颜色可以为null

.directive("logStyle", function() {
    // logStyle directive
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
           element.css(scope.$eval(attrs.logStyle));
        }
    };
});
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它发挥作用.我知道有ngStyle,但它不是我需要的.

Jon*_*Jon 16

好吧,尝试这个,但我不确定我是否完全明白你想做什么

<div ng-controller="appCtrl">
<ul>
    <li ng-repeat="item in items" ng-style="{'background-color': item.color}">
        <span ng-style="{ 'color': (item.color | contrastColor) }">{{ item.label }}</span>
    </li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)

编辑了html,昨晚无法在IE上测试,所以不得不等到今天.IE似乎不喜欢带有{{}}绑定的style属性,因此它会从DOM中删除它.我发现了这个问题https://github.com/angular/angular.js/issues/2186并且有一个带有修复程序的plunkr.