gpt4 book ai didi

javascript - ng-src 与 ng-repeat 内的 ng-if 条件仍然在后台加载图像

转载 作者:行者123 更新时间:2023-11-28 05:05:59 26 4
gpt4 key购买 nike

我有一个范围对象,其中包含具有 3 个不同图像的对象。我在 div 内显示图像,该图像重复直到范围对象的长度。我有 3 个不同的 img 标签,它们具有 ng-if 属性,并且仅一次显示 3 个图像之一。但是当我检查 chrome 开发者工具的网络部分时,我发现所有图像都是从服务器请求的,即使它们没有显示。如何防止它们加载?

<div class="container" ng-repeat="image in images">
<img ng-if="zoom == 1" ng-src="{{image.small}} alt="{{image.text}}">
<img ng-if="zoom == 2" ng-src="{{image.medium}} alt="{{image.text}}">
<img ng-if="zoom == 3" ng-src="{{image.big}} alt="{{image.text}}">
</div>

如果条件为假,ng-if不应该阻止图像加载吗?我正在使用 angularjs 1.5

最佳答案

根据this GitHub Issue您需要使用 ng-show 而不是 ng-ifng-src 来防止加载不需要的图像。

关于javascript - ng-src 与 ng-repeat 内的 ng-if 条件仍然在后台加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41747339/

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