简体   繁体   English

图像未在IE的角度页面中加载

[英]Images not loading in angular page in IE

Right now I have an angular page that makes a request to my server to get some data. 现在,我有一个角度页面,它向服务器发出请求以获取一些数据。 In this data are urls to images in S3. 在此数据中是S3中图像的URL。 Once the data has been retrieved, a variable on the scope is set with this data. 检索到数据后,将在该数据上设置作用域上的变量。 In my view I iterate through these items and make a block of html for each one. 在我看来,我要遍历这些项目,并为每个项目制作一个html块。

The issue arises in IE only (and only for some people on my team, not all of them) where instead of the images loading the failed to load image icon shows up. 该问题仅在IE中出现(并且仅对我团队中的某些人有用,而并非对所有这些人都有用),而不是在图像加载中显示“无法加载图像”图标。 Again it does not happen for everyone, it does not happen if IE console is open, it does not happen in any other browser we have tried. 同样,它不会对每个人都发生,如果IE控制台已打开,也不会发生,在我们尝试过的任何其他浏览器中也不会发生。 If I reload the page they show up as normal. 如果我重新加载页面,它们将正常显示。

Here is my controller (I have stripped out unnecessary stuff): 这是我的控制器(我去除了不必要的内容):

$http.get('/url').success(function (data, status, headers, config) {
    $scope.CardList = data;
})

Here is the relevant piece of my view: 这是我的观点的相关部分:

<div class="card-tile white_box" ng-repeat="card in CardList.Cards">
        <div class="card-tile-header pointer">
            <span class="card-month">{{card.MonthName}} {{card.Year}}</span>
        </div>
        <div class="card-tile-content pointer" >
            <img ng-src="{{ card && card.ImageUrl || ''}}" />
        </div>
    </div>

You must have using IE9, and it regarding the console.log . 您必须使用IE9,并且它与console.log有关。 Somewhere in a code you are using console.log which is failing in IE while console is not open. 您正在使用某个代码的某个位置使用console.log ,但在未打开控制台的情况下IE中失败了。

The reason is IE9 doesn't create an window.console unless we open up a console by using F12. 原因是IE9不会创建window.console除非我们使用F12打开控制台。

For avoiding such error you could define the console object in your global Javascript file which should loaded before all other custom js files 为了避免此类错误,您可以在全局Javascript文件中定义console对象,该对象应在所有其他自定义js文件之前加载

if (!window.console) {
    window.console = {};
}

if (!console.log) {
    console.log = function() {};
}

Reference answer for more details 参考答案以获取更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM