【问题标题】:Angular function call not working in IE browserAngular 函数调用在 IE 浏览器中不起作用
【发布时间】:2016-08-20 02:56:26
【问题描述】:

我最近开始研究 UI。所以我将angularjs与html一起使用。我对 Internet Explorer css 样式有疑问。我正在使用角度调用来根据字段值确定 div 的背景颜色。它在 chrome 和 firefox 中运行良好。但是在 IE 中它给出了一些错误,如下所示

这是我的 HTML 代码

<div class="row" style="border-bottom: 1px solid black; border-top: 1px solid black; padding-top: 5px; padding-bottom: 5px;margin-right:5px;margin-left:5px; margin-bottom: 5px; margin-top: 5px; clear: both; background-color: {{get_color(system.status)}}; position: relative">

这是我的角度函数

$scope.get_color = function(val){

    if (val == '0'){    
        return 'rgb(245,215,215)';
    }
    else{
        return 'rgba(211,211,211,0)';
    }
}

知道我错过了什么吗?

【问题讨论】:

    标签: javascript html css angularjs internet-explorer


    【解决方案1】:

    您的background-color 设置为{{get_color(system.status)} 的Angular 表达式,但它应该是{{get_color(system.status)}}。注意最后缺少的}

    尝试将您的 HTML 更改为:

    <div class="row" ng-style="get_color(system.status)" style="border-bottom: 1px solid black; border-top: 1px solid black; padding-top: 5px; padding-bottom: 5px;margin-right:5px;margin-left:5px; margin-bottom: 5px; margin-top: 5px; clear: both; position: relative">
    

    在您的 get_color 函数中,执行以下操作:

    $scope.get_color = function(val){
        if (val == '0'){    
            return { "background-color": 'rgb(245,215,215)' };
        }
        else{
            return { "background-color": 'rgb(211,211,211,0)' };
        }
    }
    

    总而言之,使用ng-style 并让您的函数返回一个包含您要使用的样式的对象。

    【讨论】:

    • 我已经添加了我的 html 代码。请检查,最后我有两个大括号,我不知道为什么在浏览器中渲染时它丢失了。直到现在我才注意到这一点。并且相同的代码在其他浏览器(如 chrome 和 firefox)中运行良好,它也呈现第二个花括号
    • html应该是怎样的??我已经添加了我的角度函数。我应该做些什么改变?
    • 抱歉,HTML 被隐藏了……再检查一遍。
    • 成功了!!!谢谢 :) 但是当我像我提到的那样使用时它不起作用的原因是什么?
    • 老实说,我不知道。这是一个我以前从未听说过的奇怪问题。幸运的是,使用 Angular,通常总有另一种方式来做某事。
    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 2023-03-23
    • 2016-07-19
    • 1970-01-01
    • 2013-01-21
    • 2017-01-07
    • 2011-04-30
    • 2015-05-20
    相关资源
    最近更新 更多