使用角度ng样式时出现问题,在IE中未更新

Problems using angular ng-style, not updating in IE

本文关键字:问题 IE 更新 ng 样式      更新时间:2023-09-26

我在 Angular 中创建一个简单的指令,它生成一个滚动条来显示一些产品。

我遇到一部分代码的问题。

            <ul ng-style="{'margin-left':{{currentMargin}}+'px'}">
                <li ng-repeat="tyre in tyres" ng-style="{'width':{{liWidth}}+'px'}">
                    <div class="imageContainer"><img src="../Images/eutl/{{tyre.image}}"/></div>
                    <div class="details">
                        <h3>{{tyre.name}}</h3>
                        <a href="{{tyre.link}}">About this tire</a>
                    </div>
                </li>
            </ul>
and this is what it looks like in the browser once executed
<ul ng-style="{'margin-left':0+'px'}">
<!-- ngRepeat: tyre in tyres -->
<li ng-repeat="tyre in tyres" ng-style="{'width':265+'px'}" class="ng-scope" style="width: 265px;">
    <div class="imageContainer"><img src="../Images/eutl/tire.jpg"></div>
    <div class="details">
        <h3 class="ng-binding">Fuel Efficient</h3>
        <a href="#">About this tire</a>
    </div>
</li>
<!-- end ngRepeat: tyre in tyres --></ul>

在我的页面上执行此操作后,我得到了滚动条,"li"元素中的 ng 样式正确显示,而"ul"的 ng 样式则没有。

我已经尝试了多种解决方案,甚至尝试从"li"元素添加完全相同的 ng 样式,但它没有得到处理,也没有添加任何样式。

谁能帮助我指出我的标记中的错误或一个ng样式在Li元素上工作而另一个在UL本身上不起作用的可能原因?

我遇到的另一个问题是当前边际的值在IE8/9等中没有更新。

谢谢

ng-style接受计算结果为对象的 Angular 表达式。这意味着,如果要在该表达式中使用变量,可以直接使用它(不带双卷曲):

ng-style="{width: liWidth + 'px'}"

当您想要将动态内插值插入到接受字符串的参数(如 <img alt="{{product.name}} logo"> )时,使用双卷曲。然后,将表达式放在这些括号

尝试做:

ng-style="{'width':liWidth+'px'}">

没有大括号,很多ng指令不喜欢