如何在Angular 9中重新定位图像

问题描述

美好的一天社区

我正在使用Angular 9构建平台,用户可以在其中上传图片,并且可以在其个人资料页面中查看它。 我希望当用户上传新图像时,该图像成为列表中的第一张图像,而不是成为列表中的最后一张图像。请问我该如何实现?

image.component.html

<div class="colorlib-gallery silli">
            <div class="container">
                <div class="row row-pb-md">
                    <div class="col-md-3 col-6 no-gutters video"  *ngFor="let fileUpload of fileUploads">
                        <a href="{{fileUpload?.url}}" class="image-popup-link animate-box"><img class="img-responsive" src="{{fileUpload?.url}}" alt="img" style="padding: 10px; ">
                            <div class="desc text-center">
                                
                                <p class="category"><span></span></p>
                            </div>
                        </a>                   
                    </div>
                </div>          
            </div>
    </div>

等待回应。 谢谢

解决方法

可能您正在使用fileUploads.push函数(例如fileUploads.push(file))将新文件添加到fileUploads数组中。 只需使用取消移位功能代替推入即可。

例如; fileUploads.unshift(file);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...