我已經構建了一個利用Instagram API來提取圖像的Angular應用程序。如果用戶以後刪除了圖像,我最終會看到破損的圖像(404)。 我試圖用jQuery來隱藏包含這些(破碎)圖像的div,但它們仍然出現。如何在Angular應用程序中隱藏破碎的圖像
我放在下面的jQuery的「custom.js」文件,我在我的「的index.html」文件中引用:
$(document).ready(function() {
$("img").error(function() {
$(this).parent().hide();
});
});
我引用的jQuery的頭,然後「custom.js」的是index.html,如下:
<script src="libs/jquery/dist/jquery.min.js"></script>
<script src="js/custom.js"></script>
...這裏是我試圖在此jQuery的應用到HTML:
<a ng-href="{{image.link}}" target="_blank" title="{{image.text}}"><img ng-src="{{image.img}}" alt="" class="img-responsive" ng-style="homeColors" id="image"></a>
爲什麼不刪除?你不需要再顯示它。 – cychoi 2014-11-08 05:19:29
@cychoi,刪除也是一個選項。問題是,上面的jQuery目前沒有工作,我不明白爲什麼。 – MattDionis 2014-11-10 15:47:25
您提供的代碼有效。檢查這裏:http://jsfiddle.net/fqxw0dqg/ – cychoi 2014-11-12 17:03:14