首页 > 解决方案 > 如何使用 Angular 5 在网页上隐藏图像

问题描述

这里我是使用 ng2-file-input 输入图像,图像输入成功但图像显示在网页上,所以当我上传图像时,我不希望网页中显示的图像隐藏图像,因为它上传了后端。下面我分享了我的 HTML 代码。如果您有任何疑问,请在评论中问我,我会澄清。提前谢谢您。

<ng2-file-input class="Browse"  (onAction)="onAction($event)" [multiple]="false" [hidden]="Key"  [extensions]="['doc','pdf','txt','jpg','png']"></ng2-file-input>

在此处输入图像描述

标签: angular

解决方案


在您的代码中,请检查您
showPreviews:true;对 false 的更改并停止显示上传图片的预览

Ng2FileInputModule.forRoot(
          {
             dropText:"Drop file here";
             browseText:"Browse";
             removeText:"Remove";
             invalidFileText:"You have picked an invalid or disallowed file."
             invalidFileTimeout:8000;
             removable:true;
             multiple:false;
             showPreviews:true;
             extensions:['jpg'];
          }
        ),

或者你试试这个 [showPreviews]:false添加在下面的行

<ng2-file-input class="Browse"  (onAction)="onAction($event)" [multiple]="false" [hidden]="Key" [showPreviews]:false  [extensions]="['doc','pdf','txt','jpg','png']"></ng2-file-input>

推荐阅读