0

我的指令,完全在Chrome,但不是在IE8不改变:宽度在IE

app.directive('barMax', function ($compile) { 
    return { 
     restrict: 'E', 
     scope: { 
      current: '=', 
      max: '=' 
     }, 
     link: function postLink(scope, element, attrs) { 
      scope.$watch('max', function (newValue) { 
       var newContent = ''; 
       newContent += '<div class="bottom" style="width:{{max*2}}px;">&nbsp;</div><div class="mid" ng-class="{greater: current >= max, less: current < max}" style="width:{{current*2}}px;">&nbsp;</div><div class="top" style="height:17px;"><div style="width:41%;float:left;margin-top:2px;margin-left:2px;"></div><div style="float:left;width:50%;margin-top:2px;"></div></div>'; 
       element.append($compile(newContent)(scope)); 
      }); 
     } 
    }; 
}); 

在IE中会发生什么事是......例如以前可能最大:100和电流:100,则灰色条的宽度为100px,彩色条的宽度为100px。由于电流等于max,所以彩色条的颜色将是绿色,然后我将scope.changeability更新为max:130和current:90,所以我应该预计灰色条的宽度为130px,彩条应该有90px的宽度,但宽度不会更新。颜色是正确的。问题是宽度,因为它没有更新。

我还添加了填充工具

<!--[if lte IE 8]> 
    <script> 
     document.createElement('bar-max'); 
    </script> 
<![endif]--> 
+0

你能后全部用于以下类的CSS所有的一些例子:顶部,中部,底部,更多,更少。此外,内联样式+插值对我来说看起来很惹人讨厌。我会使用动态CSS的'element.css'函数。 – mortalapeman

回答