使用IE在Angular模板中设置HTML样式的问题

时间:2015-08-28 20:41:13

标签: javascript html css angularjs internet-explorer

在Internet Explorer中对数据阵列执行重复操作时,我无法设置元素样式。在Safari,Chrome,Firefox中一切正常,但出于某种原因,IE并不喜欢我做事的方式。

任何指导都会非常感激。

我正在使用自定义过滤器进行ng-repeat,您将在下面看到

.filter('range', function() {return function(input, total) {total = parseInt(total);for (var i=0; i<total; i++)input.push(i);return input; };})

基本上,ng-style内的任何内容都不会在IE中翻译。

<div ng-repeat="key in [] | range:documentData.info.pages">
    <div ng-if="(key+1) <= documentData.info.pages" ng-style="width:{{ documentData.style.width }}px;height:{{ documentData.style.height }}">
        <div class="formBackground" ng-style="background-image:url('/images/templates/{{ documentData.info.uid }}/{{ documentData.info.id }}/{{ (key+1) }}.png')">  
            Stuff
        </div>
    </div>
</div>  

1 个答案:

答案 0 :(得分:2)

您的问题可能是由于您用于设置宽度和高度的字符串语法。而是尝试使用对象文字语法,即{width:widthProp, height:heightProp}

ng-style="{width:documentData.style.width, height: documentData.style.height }"

ng-style="{'background-image':'url(/images/templates/{{documentData.info.uid}}/{{documentData.info.id}}/{{(key+1)}}.png)'}"