如何使用角度4检查资产文件夹中是否存在图像
发布时间:2020-12-17 17:29:29 所属栏目:安全 来源:网络整理
导读:我需要使用Angular 4检查文件夹中是否存在图像.我有一个从服务器返回的图像名称列表.我需要的是检查资产文件夹中是否存在该图像.任何帮助或想法都会很棒. 解决方法 试试这个.答案发现于 link // The "callback" argument is called with either true or fals
我需要使用Angular 4检查文件夹中是否存在图像.我有一个从服务器返回的图像名称列表.我需要的是检查资产文件夹中是否存在该图像.任何帮助或想法都会很棒.
解决方法
试试这个.答案发现于
link
// The "callback" argument is called with either true or false // depending on whether the image at "url" exists or not. function imageExists(url,callback) { var img = new Image(); img.onload = function() { callback(true); }; img.onerror = function() { callback(false); }; img.src = url; } // Sample usage var imageUrl = 'http://www.google.com/images/srpr/nav_logo14.png'; imageExists(imageUrl,function(exists) { console.log('RESULT: url=' + imageUrl + ',exists=' + exists); }); 我想警告你.由于它将图像加载到内存(如果存在),它可以帮助您解决性能问题,以便立即检查更多图像. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |