angularjs 过滤器在 IE9 中未执行

angularjs filter not executing in IE9

本文关键字:执行 IE9 过滤器 angularjs      更新时间:2023-09-26

我正在运行AngularJS 1.2.22,我似乎在使用IE9和我编写的自定义过滤器时遇到问题。 它在Chrome和Firefox中运行良好,但当然不是我真正需要的浏览器。

我在 标签中有两个过滤器:一个用于返回字体真棒图标名称,另一个用于提供颜色样式。 问题是一个过滤器运行正常,它给了我图标名称,但另一个过滤器没有,它给了我颜色。

这是我的网页

<td>
    <i tooltip="{{d.Validation}}" class='fa {{d.StatusIndicator | statusIcon}}'
        style="color: {{d.StatusIndicator | statusIconColor}}; font-size: 1.25em;"></i>
</td>

还有我的过滤器源:

app.filter('statusIcon', function() {
    return function(item) {
        switch (item) {
        case 'Y':
            return "fa-exclamation-circle";
        case 'R':
            return "fa-exclamation-triangle";
        case 'G':
            return "fa-check-circle";
        default:
            return "";
        }
    };
});
app.filter('statusIconColor', function() {
    return function(item) {
        switch (item) {
        case 'Y':
            return "#B2B200";
        case 'R':
            return "red";
        case 'G':
            return "green";
        default:
            return "green";
        }
    };
});

当我在 Firefox 和 IE 上打开开发工具时,我可以看到 Firefox 中正确呈现的"颜色"样式,但在 IE 中根本没有"颜色"样式。 我在Firefox的"statusIconColor"过滤器中看到断点命中,但在IE中没有,这让我相信过滤器甚至没有在IE中被调用。

"statusIcon"过滤器中的断点在两个浏览器中都命中,但在"statusIconColor"中不会命中。 哗啦啦!

并且没有控制台错误消息。

我将不胜感激任何建议。柯瑞。

这正是

您应该使用ngAttrStyle指令的情况:

ng-attr-style="color: {{d.StatusIndicator | statusIconColor}}; font-size: 1.25em;"

但是,我会更好地使用ngStyle并避免为此目的使用过滤器。您可以改用控制器函数。

显然,IE color: {{d.StatusIndicator | statusIconColor}}; font-size: 1.25em;字面上应用这些样式,因此ngAttrStyle指令仅在插入后设置style属性。