gpt4 book ai didi

angular - 我如何使用angular 4检查 Assets 文件夹中是否存在图像

转载 作者:太空狗 更新时间:2023-10-29 17:33:32 24 4
gpt4 key购买 nike

我需要使用 Angular 4 检查文件夹中是否存在图像。我有一个从服务器返回的图像名称列表。我需要的是检查 Assets 文件夹中是否存在该图像。任何帮助或想法都会很棒。

最佳答案

试试这个。在 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);
});

我想警告你。小心它,它可能会使您遇到一次检查更多图像的性能问题,因为它会将图像加载到内存中(如果存在)。

关于angular - 我如何使用angular 4检查 Assets 文件夹中是否存在图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47282727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com